Stand in Line Can't seem to figure it out

Tell us what’s happening:
A little stuck here, can’t quite seem to figure out what I’m doing wrong here…

Passes everything but the following two:
nextInLine([2], 1)should return2nextInLine([5,6,7,8,9], 1) should return 5

Your code so far


function nextInLine(arr, item) {
  // Your code here
arr.push(item);
var removed = 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([2, 1]); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));

Your browser information:

User Agent is: Mozilla/5.0 (X11; CrOS x86_64 12239.67.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.102 Safari/537.36.

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

You’re supposed to be returning the value that way removed, not the value that has been added to the array.

Right so I tried that, still doesn’t work. Is that what you meant below?

function nextInLine(arr, item) {

// Your code here

arr.push(item);

var removed = arr.shift();

return removed; // Change this line

}

// Test Setup

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

// Display Code

console.log("Before: " + JSON.stringify(testArr));

console.log(nextInLine([2, 1]); // Modify this line to test

console.log("After: " + JSON.stringify(testArr));

Got it to work, had to change my test code to test the last 2 codes, thanks!

1 Like