I got this question correct but I don’t understand exactly how it works:
How was “testArr[]” updatd with the new values?
Since i’m just returning “item” and i’m not returning ‘arr’, how does “testArr” know its values were changed? I’ve operated on ‘arr[]’ using push() and shift() but never returned it.
You can see the contents of ‘testArr’ is ouput via the console after I call 'nextInLine()"
function nextInLine(arr, item) {
// Your code here
arr.push(item);
item = arr.shift();
return item ; // Change this line
}
// Test Setup
var testArr = [1,2,3,4,5];
// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 10)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));