Why is this function printing several arrays to console and summing the array values?

Shouldn’t the following code only print [1, 2, 3, 4] for var all? It seems to be adding each value of the array

function sumAll(arr, num) {
    
	var min = Math.min.apply(null, arr);
	var max = Math.max.apply(null, arr);
	var all = [];
	
	for(i = 0; i <= max; i++) {
	  all.push(i);
    }
  console.log(all);
}	

sumAll([1, 4]);

Did you write it in the fCC editor? In that case your function is run with several inputs to check if your code passes the tests.

1 Like

Ah, thanks! I was really confused.