Use Destructuring Assignment with the Rest Parameter to Reassign Array Elements

Hi, I stormed my brain for 2 hours and this is the best I could come up with. It satisfies 3 out of 4 requirements, the one missing being " Destructuring on list should be used".
Would really appreciate some hint. Thanks.

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

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

link: https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/es6/use-destructuring-assignment-with-the-rest-parameter-to-reassign-array-elements

Please post a link to the challenge.

yep, done this, i thought the title is enough

It looks like you changed too much code?

Try to reset and do not change anything above or below the lines indicated by the comments

Yes, I didnt noticed it. Now its all wrong, back to square 1, I guess.

You had the correct idea. Just the wrong variable.

shorterList is not defined, that`s all i keep getting no matter what i change

ok, thanks for nothing, i`ll do it alone eventually.

If you reset the code you will see it was defined as a const originally.

Why are you being rude?

I am just stating what I think: that I didnt receive in this particular instance the help that I hoped for. On the other hand I realize this is a free resource, I am in no position to demand something. However, right or wrong as I might be it still doesnt qualify as being “rude” in my honest opinion.

You may not appreciate my spending my own time (which I volunteer) to suggest to you where the mistake was made in the code, that does not mean that you may denigrate this as “nothing”.

Thanks for your honesty. I will use my time elsewhere.

I managed by myself to find the correct solution:

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

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

We have blurred this solution so that users who have not completed this challenge can read the discussion in this thread without giving away the solution.

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