Tell us what’s happening:
I didn’t get this question correctly i.e what is the use of var testArr = [1,2,3,4,5]; in this question.
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.
Your code so far
function nextInLine(arr, item) {
// Only change code below this line
arr.push(item);
var removed = arr.shift();
return removed;
return item;
// Only change code above this line
}
// Setup
var testArr = [1,2,3,4,5];
// Display code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 6));
console.log("After: " + JSON.stringify(testArr));
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36
.
Challenge: Stand in Line
Link to the challenge: