im honestly not sure how im removing the first two values
function removeFirstTwo(list) {
// Only change code below this line
[a , b , ...arr] = [list] ;
const shorterList = arr
// 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);
i tried variations of this
The list variable is an array. Are you sure you need to put it inside another array? Also, I think you want to keep the const at the start of this line.
Technically, you should be able to do this by only changing the one line between the comments. But I think there might be a bug in the tests that are keeping it from passing. I’ll look into this a little more and let you know what I find.
As far as your desctructuring, you are doing that correctly. The first value in list will go into a, the second value will go into b and the remainder of the list will go into arr.
i see about the list variable… i don’t know that i originally wrote it that way or if i started getting fed up and confused
haha
function removeFirstTwo(list) {
// Only change code below this line
[a , b , ...arr] = list ;
const shorterList = arr
// 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);
Im still getting a is not defined
Ya, there appears to be a bug in the test. In your destructuring you must use the variable name shorterList instead of arr (and then you would return shorterList as well). I’m guessing this challenge was updated recently and it used to require shorterList as the variable name but shouldn’t any more, but the test that required it wasn’t changed.
So once you removed the brackets around list then your destructuring is fine and you should just be able to return arr. But this bug is preventing that and you just need to use shorterList for the variable name instead.
function removeFirstTwo(list) {
// Only change code below this line
[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);
Is this ^^^^ what you meant
cuz im still getting
a is not defined
is it because a and b meant nothing until they were assigned a variable status that IS ALSO (??) a PART of an array deconstruction…
if that makes any sense
I’m not sure I understand exactly what you are asking. Can you try to be as specific as possible.
And another update. I think both you and I were seeing an older version of this challenge that used the variable name arr. After several cache/hard refreshes I am now seeing that the challenge does use the variable name shorterList. The original code for the challenge is now:
function removeFirstTwo(list) {
// Only change code below this line
const shorterList = list; // Change this line
// Only change code above this line
return shorterList;
}
And you should only change the line between the comments in order to pass this challenge (which you have done). So using shorterList in the destructuring is the way to go.
i meant why did i need the const variable assignment for the destructuring… why does it not recognize a in the
destructuring without the variable assignment?
First, you always want to either use const or let when declaring variables. That is just a best practice and you should always follow it.
But to answer your question, I’m not sure why FCC is giving that reference error if you don’t. I’m guessing it has something to do with the testing environment. If I run this through node or my browser without using const or let it works just fine.
But really, this isn’t a question we need to answer because you should always use either const or let
I get that
I just wanted to make sure i was understanding my environment properly… like am i understanding js enough to see the fact that…
“That can work”