How Does the Following Sum to 10?

Question: How does this Sum to 10? Will someone please explain ?

My understanding: Splice is removing numbers from the const, which would mean the sum of whats left is 21…

Challenge: We’ve initialized an array arr . Use splice() to remove elements from arr , so that it only contains elements that sum to the value of 10 .

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);

HI @TonyZebra14 !

This code here

tells the computer to start at index 1 and delete 4 elements.
In your console.log you should see this result for the array.

[2, 5, 2, 1]

If you add up those numbers it will equal ten.

Here are the docs on splice if you need a deeper understanding.

Hope that helps!

1 Like

Makes way more sense, thank you. Will also give this a read.

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