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.

PHOTO EMBED

Wed Jun 30 2021 04:41:53 GMT+0000 (Coordinated Universal Time)

Saved by @salmoon231

function nextInLine(arr, item) {
  // Only change code below this line
  arr.push(item);
 
  return  arr.shift(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));
content_copyCOPY

https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/stand-in-line