How to do the Stand In Line challenge?

For me that is the 2nd test. The 1st test passes which is

nextInLine([], 1) should return 1

So howcome this wouldnā€™t work?

function nextInLine(arr, item) {
// Your code here
.pop([2], 1);

return nextInLine; // 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));

.pop should be added to the array so
myArray.pop(); is the correct syntax. Read the docs!
return nextInLine;
nextInLine is a function so why return the name of the function??
You are asked to return the item removed last. Imagine a queue.

Sorry, I meant this, pasted the wrong code

function nextInLine(arr, item) {
// Your code here
.push(testArr).pop(testArr);

return nextInLine; // 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));

Dude, itā€™s confusing as hell, you have no idea.

Itā€™s the process itself, thereā€™s no guidelines as to how to go about what process to take and I think thatā€™s why Im getting hardcore confused. Itā€™s just a bunch of mumbo jumbo scrambled together that means nothing basically. By nothing I mean random numbers and the word array and num in the problem itself etc.

Write a function nextInLine which takes an array (arr) and a number (item) as arguments. Add the number to the end of the array

You can do this with arr.push(item);
https://www.w3schools.com/jsref/jsref_push.asp

Hereā€™s waht I would write to your instruction above.

function nextInLine(arr, 23) {
var array = [1,2,3];
array.push([4]);
}
nextInLine();

The next part:
then remove the first element of array.
You can do this with var x = arr.shift(); as the return from the shift function will be saved in var x;
https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_shift_return
Full solution:

Not sure what you mean by ā€œsaved in var xā€ because thereā€™s no storage device involved but here what I would do then.

function nextInLine(arr, 23) {
var array = [1,2,3];
array.push([4]);
array.shift([0]);
}
nextInLine();

I did [0] to remove the first number in the array.

You donā€™t actually need var x. You can return the value out of the function if you know that method?
Anyway. I am off to bed. You might get some help in the gitter chat if you still need.

Below is my first step

nextInLine([2], 1) should return 2

Itā€™s telling me what it ā€œshouldā€ be, but how am I supposed to know what to actually start writing? Like how do you take a problem and automatically ā€œknowā€ what to start writing to solve the problem? Like do I start with a function or a variable or a loop or an if/else or how do you know what to start writing?

For example, the first step (above) says nextInLine([2], 1) but I donā€™t even see where it says that or is displayed like that in the actual problem at all. This makes no sense literally at all.

Okay, hey man, thanks for taking the time to try and explain it though. I appreciate it.

1 Like

Dude Iā€™m right there with you. I donā€™t understand this at all and none of these explanations are helping.