Stand in Line - Am I right?

Tell us what’s happening:

Hey good folks! I was hoping you could tell me if I am thinking of this the right way?
This was giving me some headache. But I think I figured it out.

function nextInLine(arr, item) { // A function named nextInLine. Inside the parenthesis is parameters that act as placeholders for arguments thats defined when we call the function.

arr.push(item); // This one was troubling me. But is it right that here we are saying: Insert the “item” argument at the back of the line?

return arr.shift(); // After inserting the “item” at the back of the line, return the “arr” argument, but at the same time, remove the first item? Otherwise we would have six numbers in the array?

}

// Test Setup
var testArr = [1,2,3,4,5]; // This is a variable with array

// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 6)); // Here we call the nextInLine and pass the argument "testArr and the number 6. That gives us 2,3,4,5,6 in the “testArr” variable?
console.log("After: " + JSON.stringify(testArr));

Thanks so much!

Your code so far

function nextInLine(arr, item) {
  // Your code here
  arr.push(item);
  
  return arr.shift();  // Change this line
}

// Test Setup
var testArr = [1,2,3,4,5];

// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 50)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36 Edge/15.15063.

Link to the challenge:

Thanks so much for your answer @camperextraordinaire
So does that mean following:

  1. We are passing testArr, wich is 1, 2, 3, 4, 5 into the nextInLine function.
  2. The function takes testArr, and put “item” at the back of the line. (testArr now has six numbers?)
  3. Then it removes and stores the first item (1). (Now testArr is back to five numbers?) And return the first item (1). That means that the number 1 is displayed.
  4. Finally this new testArr is printed to the console.

Does that sound about right?

That’s brilliant! Thank you so much for taking the time. I really appreciate it. That modification made it really clear. Great help