How would i make this queue work?

i need it to not only take off the first obj and put a new obj at the end, i need to return the first obj too. how would i do this without adding a parameter or changing item?

function nextInLine(arr, item) {
  // Only change code below this line
  arr.shift();
  arr.push(item);
  item = arr[0];
  return item;
  // Only change code above this line
}

// Setup
const 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));
console.log(nextInLine([5, 6, 7, 8, 9], 1));
console.log(nextInLine([2, 1]));

Try googling how shift works in javascript.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.