question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

code passes all the test cases in browser console(chrome) but fails in free code camp page.

See original GitHub issue

Inventory 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:closed
  • Created 7 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
UXsreecommented, Nov 18, 2016

thanks guys!

0reactions
systimoticcommented, Nov 17, 2016

I can confirm that this appears to be an issue in the code. After replacing all of the instances of curInv inside the function with arr1 and all of the newInv ones with arr2, as well as returning the tempArray, 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!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found