function sumAll(arr) {
var max = arr.reduce(function(a, b) {
return Math.max(a, b);
});
var min = arr.reduce(function(a, b) {
return Math.min(a, b);
});
for(var i=min+1;i<max;i++){
arr.push(i);
}
var total = arr.reduce(function(sum, value) {
return sum + value;
}, 0);
My code is getting the correct answer but is not allowing me to submit. I had this issue before, not sure if its my code or the site?
var sum = 0;
function sumAll(arr) {
arr.sort(function(a, b) {
return a - b;
});
while (arr[0] <= arr[1]) {
sum = sum + arr[0];
arr[0]++;
}
return sum;
}
It is not very short or efficient but here is my solution. Please let me know what you think. Quick question; may be I am blind but why there are no comments from 2019. Is it because there are enough solutions shown on the forum? Thank you.
function sumAll(arr) {
arr.sort(function(a,b){
return a-b;
});
console.log(arr);
let i = 1;
let y = [];
while(arr[0] + i < arr[arr.length-1]){
y.push(arr[0] + i);
i++;
}
let z = arr.concat(y);
return z.reduce((a,b) => a+b);
}
sumAll([10, 5]);