Inventory Update- 88, "Bowling Ball" - 3rd test case wrong

Inventory Update- 88, "Bowling Ball" - 3rd test case wrong
0

#1

**Tell us what’s happening:
updateInventory([[21, “Bowling Ball”], [2, “Dirty Sock”], [1, “Hair Pin”], [5, “Microphone”]], [[2, “Hair Pin”], [3, “Half-Eaten Apple”], [67, “Bowling Ball”], [7, “Toothpaste”]]) should return [[88, “Bowling Ball”], [2, “Dirty Sock”], [3, “Hair Pin”], [3, “Half-Eaten Apple”], [5, “Microphone”], [7, “Toothpaste”]].
Passed

88, “Bowling Ball” is wrong this should be 67

third test case is wrong . **

Your code so far




const convertIntoObject=arr=>{
    const inv={};
     arr.forEach((item)=>{
        inv[item[1]]=item[0]
    })

    return inv;
}

const convertToSortedArray= obj=>{
    const newArr=[];
     Object.keys(obj).sort().forEach((key)=>{
        newArr.push([obj[key], key])
    })
    return newArr;

}



function updateInventory(arr1, arr2) {
    // All inventory must be accounted for or you're fired!
    const currInv= convertIntoObject(arr1);
    const newInv=convertIntoObject(arr2);
    const updatedInv=Object.assign({}, currInv, newInv);
console.log(JSON.stringify(convertToSortedArray(updatedInv)));
return convertToSortedArray(updatedInv)

    
 
}

// 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);

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/coding-interview-prep/algorithms/inventory-update/


#2

If the current inventory array has 21 Bowling Balls and the new delivery array has 67 Bowling Balls, then new inventory for Bowling Balls is 88 not 67. The test case is correct, but your code is not.


#3

Ohh yes, I made a mistake. I thought you have to update the old with new values. turns out we have to add old+new if old exists. Thanks for letting me know.

Sorry for wasting time. Need to read questions more carefully before solving.