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.