Stand in Line question confusing

‘Add the number to the end of the array, then remove the first element of the array.’

the number - what number???

Help please, really confuesd by the wording of this question.


The full instructions are

Write a function nextInLine which takes an array ( arr ) and a number ( item ) as arguments.

Add the number to the end of the array, then remove the first element of the array.

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

The phrase “the number” in the second sentence is referring to the phrase “the number” in the previous sentence, which is referring to the function argument item.

The phrase in the previous sentence is ‘a number’ not ‘the number’. You may think I’m splitting hairs - I’m not, I’m confused.

Repeating the same words isn’t helping, I’m looking for an alternative wording, not the same one verbatum.

Being pedantic about the non-existant difference between “a number” and “the number” in these sentences is confusing you.

Using different words:

The challenge wants you to put item at the end of arr, remove the first thing stored in arr, and then return the thing that you removed.

Not being pedantic, I thought I pre-empted that. ’ A number’ suggests something non specific whereas ‘the number’ suggests I’m missing something, which I am.

Thank you for your efforts though.

first it says “a number” because it can be any number
then it says “the number” because it’s the same number from the first line

1 Like

I’m sorry if you don’t care for the word pedantic. I only mean that you are inserting a distinction that does not exit in the problem description by focusing on a narrow, literal distinction between “a” and “the” without context.

The only two things that exist are the function arguments arr and item. Anywhere you see “the array”, you can instead insert arr in the sentence. Anywhere you see “a number” or “the number” you can instead use item in the sentence.

I get all that, thank you. I underdstand removing the first element of the array, i just don’t know what determines the number (or item) that I insert after the array, and I see nothing in the question that explains this.

The number you insert (item) is determined when the function is called (just like the specific array arr that you’re using).

This is really a key idea for functions. Functions work for any valid inputs. That is to say, your function needs to do the same behaviour for any pair of arr and item that is passed into the function.

In the specific case of this function, the test suite will try a few different numbers item and arrays arr to verify that your function has the correct output, but the exact values of item and arr do not matter when writing the function.

Thank you.

I think the ‘queue’ reference was conflicting me between simply pushing the number 6 in sequence with the test array [1,2,3,4,5], and choosing any number at random using the ‘item’ placeholder. That’s why the ‘a number’ and ‘the number’ phrases were making me look harder for a reason to be picking ‘6’!!

Thank you both again, and for your patience.

Ah. A queue in programming is just like a queue (line) at a supermarket checkout. A person (or item) shows up at the end, and a different person (the return value in this case) leaves once they have finished paying. Just like at the checkout, any person/item can show up to join the queue.

This is different than the other common data structure, a stack. A stack is really like a stack of plates. You add plates to the top of the stack when putting them away, and you take plates off of the top of the stack when you need them.

Other phrases you will see are FIFO (first in, first out) for a queue and FILO (first in, last out) for a stack.


Thanks Jeremy

1 Like

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