Hi guys, I have a little don’t understand why
arr.shift(); return arr.shift();
The result with console.log
return 2
.
But when I follow the hint and wrap my array in var
it return 1
in the console.log
function nextInLine(arr, item) {
// Your code here
arr.push(item); // at this line, arr equals [1, 2, 3, 4, 5, 6]
arr.shift(); // at this line, arr equals [2, 3, 4, 5, 6]
return arr.shift(); // Change this line
}
// Test Setup
var testArr = [1,2,3,4,5];
// Display Code
console.log(nextInLine(testArr, 6)); // I get 2 but not 1. Why???
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 6)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));