Sum All Numbers in a Range: I can not pass by this code!

Tell us what’s happening:

Your code so far

function sumAll(arr) {
  var sum = [];
  for (i = Math.min(...arr); i <= Math.max(...arr); i++) {
    sum.push(i);
  }
  
  return sum.redeuc(function(a,b){ return a+b; },0);
}

sumAll([1,4]);

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.104 Safari/537.36.

Link to the challenge:

You have a typo. There is no such function as redeuc.

I am not sure what you are asking.

let me make it clear ,here is my code :

function sumAll(arr) {
var sum = [];
for (i = Math.min(…arr); i <= Math.max(…arr); i++) {
sum.push(i);
}

return sum.redeuc(function(a,b){ return a+b; },0);
}

console.log(sumAll([1,4]));

I got a error when I run it in Chrome DevTools (browser side):

Uncaught TypeError : sum.reduce is not a function

It is not error return when I run it in a terminal use node command(Node-server side) ; I am curious about why this happen?

I don’t know how else to tell you, but whether you run the above code in node or a browser, you are going to get the following error:

TypeError: sum.redeuc is not a function

There is no such function as redeuc. There is a function called reduce you can use and you will solve this challenge.

See below where I run your code on node.

I can pass any Array to arr and get correct answer back, I am using fish shell in Ubuntu 16.04 LTS, Node version 6.9.1

Yes that is the correction solution, but that is not what you were posting earlier. In your previously posted code you had

return sum.redeuc(function(a, b) ....

instead what you are showing now (which is correct):

return sum.reduce(function(a, b) ....
1 Like

Yes, you are right !!! Thank you.