Inventory Update of thee FCC wont let me proceed

Inventory Update of thee FCC wont let me proceed
0.0 0

#1

After i have the answer, why wont freecodecamp let me proceed in the inventory update section, here is my code

> var arrQty = [];
> var arrItmName = []; 
>        
> var arr = [];

> function updateInventory(arr1, arr2) {
> count = 0;
>     // All inventory must be accounted for or you're fired! 
>     $.each(arr1, (arr1Key, arr1Val)=>{ 
>      arrQty.push(arr1Val[0]);
>      arrItmName.push(arr1Val[1]);
>     });
>     
>        $.each(arr2, (arr2Key, arr2Val)=>{ 
>           if($.inArray(arr2Val[1], arrItmName) === -1){
>               arrQty.push(arr2Val[0]);
>               arrItmName.push(arr2Val[1]);
>           }else{
>               arrQty[arrItmName.indexOf(arr2Val[1])] = arrQty[arrItmName.indexOf(arr2Val[1])] + arr2Val[0];
>           }
>        });
>        for(var i=0; i<arrQty.length; i++){
>             var columns = [];
>           for(var j=0; j<arrItmName.length; j++){ 
>              columns[0] = arrQty[count];
>             columns[1] = arrItmName[count]; 
>             break;
>         }
>         arr.push(columns);
>         count++;
>        }
>        arr.sort(function(a, b){
>         if(a[1] < b[1]) return -1;
>         if(a[1] > b[1]) return 1;
>         return 0;
> });
>     return arr;
> }

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

#2

I cleaned up your code.
You need to use triple backticks to post code to the forum.
See this post for details.

Avoid declaring global variables for the challenges. Try moving them inside the function.

Wait, are you using jQuery?


#3

Yes y do use jquery a lot, i have been trying to use some javascript, but sometimes i cant find or know its jquery equivalents, is there a way to know this functions in javascript.


#4

Jeez, it works, thank you, and i wonder why i never noticed this in the FCC till now.


#5

You can browse MDN. Here’s a reference page for array functions.

For $.each, you can use .forEach. Then for determining whether some value is in an array, there’s .indexOf and .includes.

Actually I’m surprised that you can use jQuery in the algorithm challenges.


#6

Thanks for that info, i tried using the .foreach on jquery and it didnt work i guess i didnt know it was for javascript, yeah, since day 1 i have been using the jquery.