Still 25% Confused about the Stand in Line script

Continuing the discussion from freeCodeCamp Challenge Guide: Stand in Line:

Initially I was able to get 50% of the way to understanding of this script challenge. The concept of adding and removing items to an array and the methods to do it made easy sense and easy work.

After reading forums I was then able to get my understanding to about 75% and complete the challenge, albeit with a gap in my understanding.

However, after re-reading the last of the two steps(I feel kinda stupid) I see now, that in order to return the removed array element, you need to store it somewhere first, i.e. in a variable or just eliminate the variable and encapsulate the removal into “return”.

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

What I would like to try and understand now about this is…“what is the greater learning takeaway here in first storing the removed array item in a variable to then remove it?” wouldn’t it work by just removing the array item using only…

arr.shift() /* or */ arr.shift(item) // ??

Why is the shifted item from the array getting returned and not the pushed item?

Because the instructions want the shifted item?

But what if the array starts empty?

It’s not the shifted item, though. You’re returning the first element that was removed. You have to push the item to the end of the array and then take out the first element and store it somewhere and then you are returning that first element.

Perhaps as a fail safe we want to store the removed element for a period of time before permanent deletion? And if you really think about datasets, there could be many more reasons to want the removed element returned. Hope that helps!