ES6 - Destructuring via rest elements

Tell us what’s happening:
Describe your issue in detail here.
Destructuring on list should be used.
i am struck in this error
Your code so far

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

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

Your browser information:

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

Challenge: ES6 - Destructuring via rest elements

Link to the challenge:

Technically, your solution is correct, but you changed things you shouldn’t have changed and it is confusing the tests. This is the starter code:

function removeFirstTwo(list) {
  // Only change code below this line
  const shorterList = list; // Change this line
  // Only change code above this line
  return shorterList;
}

The comments tell you to only change one line, but you made changes to both lines. Fix your solution so you only change the first line.

Use the given name for the variable shorterList , not the arr

As you can see, after this statement you don’t have a comment to change the line. So, the name ‘shorterList’ must stay.

You are certainly not the first to do this.

Even though the code comment and the location of the return below it do dictate that you can’t change the shorterList identifier I think it might be worth adding it to the requirements and maybe even having a test for it.

Use a destructuring assignment with the rest syntax to emulate the behavior of Array.prototype.slice(). removeFirstTwo() should return a sub-array of the original array list with the first two elements omitted and the rest of the elements added to shorterList.


Issue opened

1 Like

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