My function below is not passing any test in the Inventory Update problem, despite returning the correct output (array of length 6) and correct values according to VS code console.
My browser is Firefox 109.0. I’ve also tried disabling adblockers
Here’s my code:
function updateInventory(arr1, arr2) {
let myInv = {};
// create myInv object from arr1 array
for (idx = 0; idx < arr1.length; idx++) {
myInv[arr1[idx][1]] = arr1[idx][0];
}
// update myInv object with arr2
for (idx = 0; idx < arr2.length; idx++) {
if (myInv[arr2[idx][1]] == undefined){
myInv[arr2[idx][1]] = arr2[idx][0];
}
else {
myInv[arr2[idx][1]] = myInv[arr2[idx][1]] + arr2[idx][0];
}
}
arr1 = Object.entries(myInv); // convert the myInv object to array and assign to arr1
arr1.sort(); // sort the arr1 array alphabetically
// invert each item in arr1 array, from [name, qty] to [qty, name] format
for (idx = 0; idx < arr1.length; idx++) {
arr1[idx] = [arr1[idx][1], arr1[idx][0]];
}
return arr1;
}
VS code output for test#3
I would appreciate if someone took a look what’s wrong