I’m trying to create a new array consisting of each number ranging from 0 to the maximum number within given arguments; and then log the sum of the numbers from the new array. Any pointers? Can’t figure out what’s wrong with my code.
Your code so far
function sumAll(arr) {
var newArr = [];
var maxAmt = Math.max(arr);
var reduceFunk = function getSum(a, b){
return a + b;
};
for(var i = 0; i <= maxAmt; i++){
newArr.push(i);
}
return newArr.reduce(reduceFunk, 0);
}
sumAll([1, 4]);
Your browser information:
Your Browser User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36
.
Link to the challenge:
https://www.freecodecamp.org/challenges/sum-all-numbers-in-a-range