Basic Data Structures - Remove Items Using splice()

Tell us what’s happening:
I passed this challenge by using .splice() twice. I understand why it works. I saw the solution and understood why it works.

I understand there are usually many ways to solve a problem in programming, but are we expected to solve this using a single .splice() ? Is that the intent here?

Your code so far

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

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36 Edg/109.0.1518.78

Challenge: Basic Data Structures - Remove Items Using splice()

Link to the challenge:

Looks like the main goal of this step - introduce the splice method. So if you understood basics of how it works, then it does not matter much how exactly you managed to pass the tests I think

1 Like