I am writing this code to find missing numbers from a given array. This code works fine when i pass 1,4 as arguments but 5,10 it fails to push new items to the array. What am I doing wrong?
function sumAll(arr) {
max = Math.max(...arr);
min = Math.min(...arr);
toFill = max - min;
for (i = min + 1; i <= toFill; i++) {
arr.push(i);
}
return arr.sort().reduce((prev, curr) => prev + curr);
}
sumAll([5, 10]);