Basic JavaScript: Stand in Line flabbergasted

Okay, so… I’m a bit confused with how to deal with this.

I’ve completed the code and managed to narrow it down to

function nextInLine(arr, item) {
  // Only change code below this line
  arr.push(item);

  return(arr.shift());

  // Only change code above this line
}

While that returns as correct, I was wondering if someone could pinpoint exactly why the below 2 code ALSO returned as correct?

function nextInLine(arr, item) {
  // Only change code below this line
  arr.push(item);

  return(arr.shift(item));

  // Only change code above this line
}

and

function nextInLine(arr, item) {
  // Only change code below this line
  arr.push(item);

  var shifted = arr.shift(item);

  return(item, shifted);

  // Only change code above this line
}

In both cases, item is totally ignored but still gains a pass. Is there any specific reason to why?

shift doesn’t take an argument, so it doesn’t matter what you put in the parenthesis, it has always same behaviour

a comma separated list returns the last element, so you are returning shifted anyway

Ahh, I understand.

a) Ignores everything.

Shift is totally arrogant, hehe.

Thanks for the explanation!

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