There is a code that displays the sum of the numbers in the array, without the largest and smallest value. Can't check input value to undefined.
I tried to check this way:
if (typeof something === "undefined") { alert("something is undefined"); } But I do not pass the tests, I need to, if undefined then just output 0.
function getMaxOfArray(numArray) { return Math.max.apply(null, numArray); } function getMinOfArray(numArray) { return Math.min.apply(null, numArray); } function sumArray(numbers){ var maxPlusMin = getMaxOfArray(numbers) + getMinOfArray(numbers); if (numbers && isNaN(numbers) & (numbers.length != 0) ) { return numbers.reduce(function(sum, n){ return n + sum; }, -maxPlusMin ); } else { numbers = 0; } } alert(sumArray([ 1, 2, 3, 4, 10 ]));
return numbers;to put? Or immediatelyreturn 0;? And for example, change&? - Visman