You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The code shown in the explanation video is not in fact immutable.
Incorrect code:
console.log([
...drinks.splice(0, index),
'Mojito',
...drinks.splice(index - 1),// side note: the -1 index correction is only needed as a result of the first splice mutating the original array
]);
Explanation:
As splice mutates the original array, before the spread operator spreads it, the original array gets mutated nevertheless. Solution: copy original array with spread operator, splice it, then spread the result.
The text was updated successfully, but these errors were encountered:
Opposed to splice, slice is immutable. I'm assuming this is what you wanted to do in the first place and the error is only a typo. Beware that the index correction (-1) is now not needed anymore though.
The code shown in the explanation video is not in fact immutable.
Incorrect code:
Correct code:
Explanation:
As
splice
mutates the original array, before the spread operator spreads it, the original array gets mutated nevertheless. Solution: copy original array with spread operator, splice it, then spread the result.The text was updated successfully, but these errors were encountered: