ES6 - Destructuring via rest elements

Tell us what’s happening:

I got it, but the removeFirstTwo([1, 2, 3, 4, 5]) should return [3, 4, 5], and I shouldn’t modify the original array. I need assistance on approaching this.

Your code so far

function removeFirstTwo(list) {
  return list;
}

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

Your browser information:

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

Challenge Information:

ES6 - Destructuring via rest elements

so obviously you have to use destructuring assignment for this so have you tried to understand this example as a first step?

const [a, b, ...arr] = [1, 2, 3, 4, 5, 7];
console.log(a, b);
console.log(arr);

What do you think the 2nd log statement does?

It prints the arr, the rest of the array.

so it prints out an array? And that array is minus the first 2 values?
(Hint Hint)

Yes, it prints the array minus the first 2 values. I’m not having trouble with that. I’m having trouble with getting the whole array minus the first two values, and minus the last values.

I’m trying to be heavy-handed with the hints here.
The arr is the array minus the first 2 values.

And the objective of this exercise is ??? (double triple hint)

Is to print the value of arr.

so are you still confused as to how to return an array with all the values except the first 2?
(hint: refer to that example again?)

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