So I am trying to break this down code down to understand how it is all working as a whole but I am stuck on what it means by (list) ? I saw that the answer was const [a,b,…arr]= list; but for some reason I dont understand why this is. Why does it have to be hooked up to this list ??
Your code so far
const source = [1,2,3,4,5,6,7,8,9,10];
function removeFirstTwo(list) {
"use strict";
// Only change code below this line
const arr = list; // Change this line
// Only change code above this line
return arr;
}
const arr = removeFirstTwo(source);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36 OPR/67.0.3575.137.
Challenge: Use Destructuring Assignment with the Rest Parameter to Reassign Array Elements
Hey David, for this challenge you need to alter the left side of the equal sign of const arr = list;. The example can tell you a lot… const [a, b, ...arr] = [1, 2, 3, 4, 5, 7];
Can you see where list could belong in the example and how it would solve your problem?
I understand that writing [a,b, …arr] means that A and B would take the first 2 numbers of the list and the rest goes to ( …arr) right? So the thing that is throwing me off about this is why list? Is that just the condition of the function, like if the function calls for number instead of list would it than equal number? Also does list now hold the values of A and B?
list is a function parameter. It works just like a local variable except you can pass values to it when you call the function. You can name parameters whatever you like, but the more descriptive the better.
The list parameter is passed the array when the function is called.
// the array
const source = [1,2,3,4,5,6,7,8,9,10];
// source is the array passed into the function when called
removeFirstTwo(source);
// list is the parameter which after the function is called containers the source array
function removeFirstTwo(list) {
console.log(list === source) // true
}