I´m trying to do what it asks in Hint number 1 with a nested for loop:
You need to work through each item of the new inventory to see if it exists in the current inventory or not. Remember that the product name is stored as the second element of each sub-array: array[0][1] = "item-name"
.
But It seems it never reaches the conditional when an item is the same:
function updateInventory(arr1, arr2) {
for (let i=0; i<arr2;i++){
for (let j=0; j<arr1.length;j++){
if (arr2[i][1] === arr1[j][1]){
arr1.push(arr2[i][1])
//why the loop doesn´t get here?
}
}
}
return arr1;
}
// Example inventory lists
var curInv = [
[21, "Bowling Ball"],
[2, "Dirty Sock"],
[1, "Hair Pin"],
[5, "Microphone"]
];
var newInv = [
[2, "Hair Pin"],
[3, "Half-Eaten Apple"],
[67, "Bowling Ball"],
[7, "Toothpaste"]
];
updateInventory(curInv, newInv);
Can you please tell me what is wrong in that code, if