ES6 - Destructuring via rest elements

Tell us what’s happening:

removeFirstTwo([1, 2, 3, 4, 5])

should be

[3, 4, 5]

Your code so far

function removeFirstTwo(list) {
  return list;
}

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

console.log(sourceWithoutFirstTwo);
console.log(list.splice(2, 3));

Your browser information:

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

Challenge: ES6 - Destructuring via rest elements

Link to the challenge:

1 Like

Hey @ronikoswara795!

The code that removes first two elements from the list should be placed within removeFirstTwo function.

Also, instead of using splice, try using rest operator, like shown in the exercise description.

Here’s the example with more descriptive variable names:

const list = [1, 2, 3, 4, 5, 7]
const [firstItem, secondItem, ...listWithoutFirstTwoItems] = list

console.log(firstItem, secondItem)
console.log(listWithoutFirstTwoItems)

Hope it helps!

1 Like