I'm trying to solve the task (Sum all the numbers of the array (in F# and Haskell you get a list) except the highest and the lowest element (the value, not the index!). (The highest/lowest element is respectively only one element at each edge, even if there are more than one with the same value!))
This is my code but I am getting NaN
function sumArray(array) {
var sum;
array.sort(function(a, b) {
return a - b
});
for (var i = 1; i < array.length - 2; i++) {
return sum += array[i];
}
}
console.log(
sumArray([6, 2, 1, 8, 10])
)