Hey guys, for the Stand In Line exercise, I was able to solve it, but had a few quick questions.
The exercise:
Write a function nextInLine which takes an array (arr) and a number (item) as arguments.
Add the number to the end of the array, then remove the first element of the array.
The nextInLine function should then return the element that was removed.
My solution:
function nextInLine(arr, item) {
arr.push(item);
var arr = arr.shift();
return arr;
}
my original answer was:
function nextInLine(arr, item) {
arr.push(item);
arr.shift();
return arr.shift();
}
How come my original answer does not work and I have to set var arr? How come return arr.shift(); does not work?
Thanks a lot!!