code passes all the test cases in browser console(chrome) but fails in free code camp page.
See original GitHub issueInventory Update has an issue.
Issue Description
code passes all the test cases in browser console(chrome) but fails in free code camp page.
Browser Information
chrome
- Browser Name, Version:
- Operating System:
- Mobile, Desktop, or Tablet:
Your Code
function updateInventory(arr1, arr2) {
var tempArray = [];
curInv.forEach(function(elem, index) {
newInv.forEach(function(elem1, index1) {
if(elem1[1] === elem[1]){
// console.log("found a match");
// console.log(index1, index);
tempArray.push([elem[0]+elem1[0],elem[1]]);
curInv.splice(index,1);
newInv.splice(index1,1);
}
})
})
curInv.forEach(function(element,ind){
tempArray.push(element);
})
newInv.forEach(function(element,ind){
tempArray.push(element);
})
console.log(tempArray);
tempArray.sort(function(a, b) {
if (a[1] < b[1]) {
return -1;
}
if (a[1] > b[1]) {
return 1;
}
return 0;
});
console.log(tempArray);
}
// Example inventory lists
var curInv = [];
var newInv = [[2, "Hair Pin"], [3, "Half-Eaten Apple"], [67, "Bowling Ball"], [7, "Toothpaste"]];
updateInventory(curInv, newInv);
Screenshot
Edit (@raisedadead) : Formatted for redability, original text can found here
Issue Analytics
- State:
- Created 7 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
code passes all the test cases in browser console(chrome) but ...
Inventory Update has an issue. Issue Description code passes all the test cases in browser console(chrome) but fails in free code camp page....
Read more >All tests are passed in console - but failing while submitting ...
All tests are getting passed in the console but when I'm trying to copy-paste the live link in the solution link it's not...
Read more >Tribute page passes all tests on codepen but fails on FCC
Hey everybody, 1st post here and 1st attempt at a coding project. I have finished my tribute page on code Pen and passed...
Read more >I am not able to completely pass the challenge even though ...
The failing test from the original post tries to access tests using _api/get-tests route. When page was still working I've tried that route...
Read more >Run the Tests button not working in Chrome or Firefox
Yet again, the Run the Tests button won't work. Only this time it won't work in either Chrome or Firefox. No ticks or...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
thanks guys!
I can confirm that this appears to be an issue in the code. After replacing all of the instances of
curInv
inside the function witharr1
and all of thenewInv
ones witharr2
, as well as returning thetempArray
, the code shared above works fine.I’m closing this issue because it’s not a problem with FreeCodeCamp, but an issue in the user’s code. If you believe I’m wrong in closing this issue, please add additional information and reopen. Happy coding!