Destructuring black magic

Tell us what’s happening:
They say use spice to splice to make a new array with elements that sum to 10.
const arr = [2, 4, 5, 1, 7, 5, 2, 1];

// Only change code below this line
// they say the answer is:
arr.splice(1,4);
// but if you do that, the array becomes arr = [4,5,1,7] which sums to 17 not 10

// Only change code above this line

console.log(arr);
Describe your issue in detail here.

Your code so far


const arr = [2, 4, 5, 1, 7, 5, 2, 1];
// Only change code below this line
arr.splice(1,4);
// Only change code above this line
console.log(arr);

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36

Challenge: Remove Items Using splice()

Link to the challenge:

splice method is used to remove elements!!

so if those elements are removed, what’s left with that array, and what that equates to?

They want the resulting array to sum up to 10. as far as I can tell, the resulting array according to their answer, is [4, 5, 1, 7] which sums to 17, not 10.

if you take out [4,5,1,7] from that array, original array is left with elements which will give you ‘10’!!

btw, splice method changes ‘original array’, you can learn more about it from here

omg, that is obtuse! The directions, not your explanation!

really?! but that solves it, right?

using `splice(1,4)’ i mean

You are logging out the array. So I don’t understand why do you believe it would be [4,5,1,7]

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.