2018-10-12 15:37:13 -04:00
|
|
|
---
|
|
|
|
title: Remove Items Using splice()
|
|
|
|
---
|
2019-07-24 00:59:27 -07:00
|
|
|
# Remove Items Using splice()
|
2018-10-12 15:37:13 -04:00
|
|
|
|
2019-07-24 00:59:27 -07:00
|
|
|
---
|
|
|
|
## Problem Explanation
|
2018-10-12 15:37:13 -04:00
|
|
|
- The `splice()` function must be called on the `arr` array in order to remove 1 or more elements from the center of the array.
|
|
|
|
- The array `arr` currently adds up to the value of 16. Simply remove as many variables neccessary to return 10.
|
|
|
|
|
2019-07-24 00:59:27 -07:00
|
|
|
|
|
|
|
---
|
|
|
|
## Solutions
|
|
|
|
|
|
|
|
<details><summary>Solution 1 (Click to Show/Hide)</summary>
|
|
|
|
|
2018-10-12 15:37:13 -04:00
|
|
|
```javascript
|
|
|
|
function sumOfTen(arr) {
|
|
|
|
// change code below this line
|
2019-07-24 00:59:27 -07:00
|
|
|
arr.splice(1, 2);
|
2018-10-12 15:37:13 -04:00
|
|
|
// change code above this line
|
|
|
|
return arr.reduce((a, b) => a + b);
|
|
|
|
}
|
|
|
|
|
|
|
|
// do not change code below this line
|
|
|
|
console.log(sumOfTen([2, 5, 1, 5, 2, 1]));
|
|
|
|
```
|
2019-07-24 00:59:27 -07:00
|
|
|
</details>
|