https://www.freecodecamp.com/challenges/stand-in-line
When using push and shift function, the validation "nextInLine([5,6,7,8,9], 1) should return 5" shows I'm wrong.
However, when inserting manually the array '[5,6,7,8,9]' to testArr, and the argument '1' when calling the function, it returns '5'.
function nextInLine(arr, item) {
testArr.push(item);
item = testArr.shift();
return item; // Change this line
}
var testArr = [5,6,7,8,9];
// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 1)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));
You should be using the parameter in your function not testArr
Your code:
function nextInLine(arr, item) {
testArr.push(item);
item = testArr.shift();
return item; // Change this line
}
Correct code:
function nextInLine(arr, item) {
arr.push(item);
return arr.shift(); // Change this line
}
Got it, thanks.
Most helpful comment
Your code:
Correct code: