How can i used return value of arr.splice as parameter in function

Tell us what’s happening:

Your code so far

function sumOfTen(arr) {
  // change code below this line
  let a = arr.splice(1,1);
 let b = arr.splice(3,1);
  // 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]));

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36.

Link to the challenge:

What exactly are you trying to a here?

Currently, your code assigns a reference the an array which looks like [5] and assigns a reference to another array which looks like [2]. After these to splices, arr looks like [2, 1, 5, 1], so your reduce on arr returns the value 9 which is the sum of 2 + 1 + 5 + 1.

1 Like