Stand in Line: solution non related to description

When you read the demands,
" 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."

BUT the solution provided is the following lines in bold at the code section.

function nextInLine(arr, num) {
// Only change code below this line
> **arr.push(num);**
> **return arr.shift();**

return num;
// 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));
console.log("next: " + JSON.stringify(nextInLine));
  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36

Challenge: Stand in Line

Link to the challenge:

The code you provided does three things

  1. it puts item at the end of the arr

  2. it removes the first element of arr

  3. it returns the removed element

The description and the code match. Can you explain how you believe that the solution is unrelated to the description?

Learning to code is hard and understanding technical language is hard, but I don’t see this as a convoluted or inaccurate challenge description.

This is hard if you don’t know how to use arrays, but the solution doesn’t require ‘advanced’ array manipulation, just basic methods. We aren’t trying to trick you here.

You may want to review basic array manipulation methods like push, pull, shift, and unshift, starting here

well, I already explained. But… lets do it again. This description:
" Write a function nextInLine which takes an array ( arr ) and a number ( item ) as arguments."
was interpreted by me as, that I must use the function nextInLine() in the edition of the code. But the solution, uses push and shift only. Also, not explained before that I could push a part of the arguments alone. Obviously, this is for free and not an obligation to teach everyghing, but this description, from my pov, is super far and insuficient. Thanks for allowing us to learn to code with this console, but its just it.

Here are the instructions

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 solution exactly does this. You do understand what push and shift do?

The solution fills in the function nextInLine. The function takes the two required arguments. The function performs the required actions.

Also, not explained before that I could push a part of the arguments alone.

I don’t understand what this means. arr is an array. You can always call array methods on an array. How would you add an item to the end of an array without using push? How would you remove the first element without using shift?

Perhaps you are missing some fundamental vocabulary. Learning how to understand technical requirements is hard, but this solution exactly meets the requirements.

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