ES6 - Destructuring via rest elements

Tell us what’s happening:

Describe your issue in detail here.

So, I solved this but, was avoiding using the code that worked. Let me explain. The first set of code (code that passed) works but, in my head it doesn’t seem dynamic (which I thought it should be) in the sense that, if I were to pass different numbers within the function call, it should still only output the numbers passed without the first 2 numbers. So, I utilized .shift which seemed to work if I changed the numbers passed in the function call. However, it didn’t work because it says I was modifying the list and the code that worked doesn’t seem dynamic in the sense that, it doesn’t matter what numbers are passed in the function call, it’s only returning the numbers from the array specified within [a, b, ...list] = [1, 2, 3, 4, 5]. Also, this in my head seems to be modifying the list still but, somehow works. So, why is the code that passed below considered not modifying the list giving me a pass and why is the code using the .shift considered modifying the list and not letting me pass? Wouldn’t I usually want the more dynamic version where the array isn’t specifically written? Further, in the link Hints page, it looks as if the both solutions are modifying the list, and I’m not understanding the modification this problem is referring to. Lastly, when I look at rest parameters described in MDN Web Docs, I see them used only within the function parameters. If they are used within the function after the parameters in the block, it’s using the spread syntax. The solutions provided within the hints page, don’t use the rest parameter (as I thought it to be) but only in the const within the function. Sorry for all of the questions but, I’m pretty confused now even though I solved the problem.

Your code so far

`

javascript
function removeFirstTwo(a, b, …list) {
[a, b, …list] = [1, 2, 3, 4, 5]
console.log(list);
return list;
}

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

/* function removeFirstTwo(…list) {
const a = list[0].shift();
const b = list[0].shift();
console.log(list);
return list;
}

removeFirstTwo([1, 2, 3, 4, 5]); */


### Your browser information:

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

### Challenge Information:
ES6 - Destructuring via rest elements
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/es6/use-destructuring-assignment-with-the-rest-parameter-to-reassign-array-elements
[spoiler]
`

You appear to have created this post without editing the template. Please edit your post to Tell us what’s happening in your own words.

  • this is wrong (syntax and usecase) and not passing for me!!
  • function signature is different than what was given

your approach is very nearly what was asked in instructions, just make some adjustments, lets refer to instructions

return a sub-array of the original array list with the first two elements omitted

happy coding :slight_smile:

Hi, thanks for responding. Could you elaborate more on why the syntax and use case are wrong along with what you mean by the function signature is different than what was given?

  • syntax error
  • and not dynamic/generic
  • function signature is different than what was given initially
  • you are supposed to only bring changes to within function only

happy coding :slight_smile: