Hi,
For the task - https://www.freecodecamp.org/challenges/inventory-update, i came up with a solution which is giving right output but FCC editor is rejecting it can you please guide what i need to do here … thanks
//logic - just compare and see if value like Bowling Ball,matches, it so add their numbers and then push them in new array , then remove the values from both , left with unique values in each array now, , merge them and then ,merge with array which had similar values array with added values of items …
My JSFiddle Link - https://jsfiddle.net/jinisner/0j7rfbyq/1/
function updateInventory(arr1, arr2) {
var test = [];
var res = [];
var fin=[];
var i,j;
for( i = 0; i < curInv.length; i++){
for( j = 0; j < newInv.length;j++){
if(curInv[i][1] === newInv[j][1]){
curInv[i][0] = curInv[i][0] + newInv[j][0];
test.push(curInv[i]);
curInv.splice(i,1);
newInv.splice(j,1);
res = curInv.concat(newInv);
}
}
}
fin = test.concat(res);
console.log(fin);
return fin;
}
// 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);