Stand in Line challange

Stand in Line challange
0.0 0

#1

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

I am unable to understand this problem well enough. hence not able to find a workable solution either.
Please help.


#2

Here is the function I wrote:

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

#3

Can you please edit your topic title to reflect what you need help with instead of just posting the challenge url?

Hint #1: to part of your problem. The order in which you do things matters. When a return statement is executed, any value specified is returned and the function exits immediately, so no other code will run.


#4

All right!
Here is what I made it now:

function nextInLine(arr, item) {
 
  var toBeRet=arr[0];
  arr.push(item);
  arr.shift();
  return toBeRet;  /
}

This problem says “the nextInLine function should then return the element that was removed.”
But after running tests, error asks to return the values which were added:

nextInLine([], 5) should return a number.
nextInLine([], 1) should return 1


#5

The problem with your function is that in the test case of nextInLine([],5) there are no elements in the array passed in, so arr[0] is undefined. Read the instructions carefully. You are not following the order of operations it wants. You need to flip two of the lines.


#6

OKAY!!!
Thanks for guiding through it. :smiley: