I cant understand how the queue statement should be used?

I cant understand how the queue statement should be used?
0.0 0

#1

Tell us what’s happening:

Your code so far


function nextInLine(arr, item) {
  // Your code here
  
  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:

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

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


#2

What issue are you having? Make sure that the function “returns the element that was removed” from the array. Are you using the devTools to see what’s happening? (option, command, j)


#3

A “queue” in this case is not a statement, rather it is a type of data structure that this topic is hoping to teach you about. (I do find this topic to be very sparesly described so I am not surprised you misunderstood it).

What the exercise really wants is to teach you how to push and shift things into and out of the given array. Push puts things at the end of the array and shift takes something out from the start of the array thus creating a “queue” structure. (Like standing in line at a bank , the first guy gets to leave first, and anyone new coming joins the back of the line)

Hope this helps!


#4

i cant understand what changes should i make in the 13th line!


#5

Two of these are needed: push, pop, unshift, shift.


#6

hello again,

you do not need to make any changes outside of the function “nextInLine” to pass this challenge.
Simply think about how to use push and shift to achieve a ‘queue’ result and place the code in nextInLine function.

hope this helps.


#7

A queue in javascript is simply an array. What makes it a queue is that you only get to use 2 operations.

  1. put something in the back of the queue
  2. take something from the front of the queue

So we can use this to simulate a line like at a movie theater. And when someone shows up to this particular line in the test, we determine who is next by:

  • if no one is there, go straight in
  • if there’s people there
    • stand at the back
    • the first person goes in

You have to write this logic in code and return who the next person is in line.


#8

thanks!!I solved it.:grinning: