ES6 - Destructuring via rest elements

Tell us what’s happening:
Using the code below with the variable rest or anything other than shorterList gives an erroneous failure saying , “Destructuring on list should be used.” Destructuring IS being used on list, its just that the test only allows the code to pass when shorterList is used following the spread syntax (…). This can lead to undue confusion as to how destructuring with rest elements works. The code should pass regardless of the variable being assigned the array of values from ....

Your code so far

function removeFirstTwo(list) {
  // Only change code below this line
  const [a, b, ...rest] = list; // Change this line
  // Only change code above this line
  return rest;
}

const source = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
const sourceWithoutFirstTwo = removeFirstTwo(source);
console.log(sourceWithoutFirstTwo);

Your browser information:

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

Challenge: ES6 - Destructuring via rest elements

Link to the challenge:

You have to keep the shorterList identifier. Replace rest with that.

The test probably should mention that the shorterList identifier shouldn’t be changed. But I don’t think having that as a requirement lessens what is taught.

Hello there,

I think the instructions given, and errors given are clear:
1)

  // Only change code below this line
  const [a, b, ...rest] = list; // Change this line
  // Only change code above this line
  1. If you do use rest, instead of shorterList, the console shows this error:
ReferenceError: shorterList is not defined

If you would like to see about adding another test to the list to ensure the required values are destructured into a variable named shorterList, you are welcome to contribute to the codebase.

I stand corrected. Taking into account the borders for changing the code would prevent changing the return to rest.

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