I need help understanding why my alphabetical sort is not implemented correctly.
**Your code so far**
function updateInventory(arr1, arr2) {
let newInv = {};
let shipment = arr2;
let result =[];
// populate inventory with arr1 kv pairs
for(let item of arr1){
newInv[item[1]] = item[0]
}
//update or add items to inventory
for(let item of shipment){
if(newInv.hasOwnProperty(item[1])){
newInv[item[1]]+= item[0]
}else{
newInv[item[1]] = item[0]
}
}
//re arrange from k v to v k pairs
for(let item of Object.entries(newInv)){
result.push([item[1],item[0]])
}
//This will not sort alphabetically
result.sort((a,b)=>a[1]-b[1])
//niether will this
// result.sort((a,b)=>a[1][0] - b[1][0])
// this works to sort by quantity ascending
// result.sort((a,b)=>a[0]-b[0])
console.log(result)
return result;
}
updateInventory([[0, "Bowling Ball"], [0, "Dirty Sock"], [0, "Hair Pin"], [0, "Microphone"]], [[1, "Hair Pin"], [1, "Half-Eaten Apple"], [1, "Bowling Ball"], [1, "Toothpaste"]])
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:100.0) Gecko/20100101 Firefox/100.0
Challenge: Inventory Update
Link to the challenge: