Sum all Numbers in a Range - Spread/Rest Operator not working

Sum all Numbers in a Range - Spread/Rest Operator not working
0

#1

Hi folks,

i wrote this code in Atom, and there it is working fine. I pasted it to fcc, and there i get a error called “Spread/Rest Operator” is only available in ES6 (‘use esversion:6’) for the two lines:

var min = Math.min(...arr);
var max = Math.max(...arr);

function sumAll(arr) {
  var min = Math.min(...arr);
  console.log(min);
  var max = Math.max(...arr);
  console.log(max);

  var arrNew = [];
  for ( i = min; i < max +1; i++) {
    arrNew.push(i);
    console.log(arrNew);
  }
  var sum = arrNew.reduce(function(a, b) {
  return  a + b;
}, 0);
 console.log(sum);
}

sumAll([10, 5]);

Can anybody help me out there please? Many thanks in advance.

eazy


#2

I cleaned up your code.
You need to use triple backticks to post code to the forum.
See this post for details.


#3

You are missing the return statement at the end of you function.


#4

You should be able to submit code even if it contains ES6 syntax. It’s just the editor complaining about seeing ES6, but you should be fine.


#5

Ahh…Maaaan… :disappointed:

Thanks.