JavaScript Stand in Line Challenge

JavaScript Stand in Line Challenge
0.0 0

#1

Tell us what’s happening:
Hi campers, I’m stuck at this stage of the challenge. What I don’t understand is how to return the removed item. I have tried

return arr.shift();

but that just removes another element from the array. I have also tried the explanations in similar questions on this forum but I’m just confused as to why people are adding “item” to the push and shift functions.

Your code so far

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

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

// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 6)); // 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/65.0.3325.181 Safari/537.36.

Link to the challenge:


#2
arr.push(item) ;  // adds the value=item at the last index of array 
return arr.shift() ; // returns and removes the first element of that array 

#3

for understanding you can also do it like this

arr.push(item);
item= arr.shift();
return item;

#4

Thanks for the quick response. After re-reading the instructions it seems that I did not take the time to fully understand them.
This now works:

arr.push(item);
return arr.shift();

I should take a break and come back when I’m thinking straight. Thanks again.