Inventory Update project: My results seem to match the test data results

The little black box/window shows the results of the test - Is that correct?
See the screenshot. I moved the black box next to the test data results. Can anyone see a difference?

I am returning an array for the first test.
My result for the second test is an array with a length of 6. (Screenshot)
My result for the third test seems to match the results in the test data:

[[88, “Bowling Ball”], [2, “Dirty Sock”], [3, “Hair Pin”], [3, “Half-Eaten Apple”], [5, “Microphone”], [7, “Toothpaste”]]

Am I missing something as to why these results are not accepted?
Is there a formatting issue?
(I have been staring at the code for awhile. But, I got up and took a break to try to look at it with somewhat fresh eyes.)

Help would be appreciated.

I ran the code in a Chrome Browser and wrote the results to the console, if that is helpful.

The screenshot is to the left of the thick black line.
The console log is what is to the right of the thick black line.

CodePen file

Could you paste or send a link to your code so that I can have a closer look ?

1 Like

You’re probably using the global scope for something. It just doesn’t work for some reason.

Are you using “this” anywhere in your function ?

If so, the “this” may be referring to the global object (window) instead of your function.

Try using — “use strict”; as the first line in your function so that any references to “this” get the correct scope.

I also had this problem with one of the algorithm challenges.

Thanks for your replies.

I added a link to the CodePen file.
It is below the image.

Note: There are some alerts and a console.log statement in the code you might want to comment/uncomment.

I tested it in Chrome.

Okay, problem solved.

At the start you define 2 useless variables (currInv and newInv), and you are working strictly with thoses, hijacking the functions arguments (arr1, arr2).

You can simply replace every occurence of currInv with arr1 and newInv with arr2 to make it pass every tests.

1 Like

Ha! Yes!

Thank you very much, Mizu!

If I could give you a cookie or a candy bar through this reply, I would.

I just couldn’t see that. Been staring at the same code for too long.

1 Like