**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/