Confusion on the directions

Tell us what’s happening:
Describe your issue in detail here.
nextInLine([2], 1) should return 2

  **Your code so far**

Shouldn’t the nextInLine([2], 1) return 3?
the number 2 refers to the third object or array right?

function nextInLine(arr, item) {
// Only change code below this line
return arr.shift([]);
// Only change code above this line

// Setup
const testArr = [1, 2, 3, 4, 5];

// Display code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 6));
console.log("After: " + JSON.stringify(testArr));
  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:96.0) Gecko/20100101 Firefox/96.0

Challenge: Stand in Line

Link to the challenge:

It can’t return 3

The nextInLine function should then return the element that was removed.

for nextInLine([2], 1), 3 isn’t in that array, so its not possible to remove it from the array.

I still don’t understand, nextInLine is a function.
it is adding and removing from testArr.
testArr has 1-5 in it,
moving from 0, 2 is the third item on the list, which would be 3.
I’m not understanding my faulty logic.

This is not true. It is using whatever array is passed in as the arr argument.

So, nextInLine([2], 1) says, “use the arr = [2], add the item = 1 to the end of the arr, remove the first element of the arr, and return the removed element”

Ok, I was reading it wrong, I didn’t realize it was pulling 1 and selecting from 2.
Thank you.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.