// https://www.codewars.com/kata/576b93db1129fcf2200001e6/train/javascript function sumArray(array) { // --- simple output controls if(!array) return 0 ; if(array && Object.keys(array).length <=2) return 0; // -- find the maximum and the minimum const max = Math.max(...array); const min = Math.min(...array); // -- delete the maximum and the minimum let index = array.indexOf(max); array.splice(index, 1); index = array.indexOf(min); array.splice(index, 1); // -- sum return array.reduce((a, b) => a + b, 0) } console.log( sumArray(null) , 0 ); console.log( sumArray([ ]) , 0 ); console.log( sumArray([ 3 ]) , 0 ); console.log( sumArray([ 3, 5 ]) , 0 ); console.log( sumArray([ 6, 2, 1, 8, 10 ]) , 16 ); console.log( sumArray([ 0, 1, 6, 10, 10 ]) , 17 ); console.log( sumArray([ -6, -20, -1, -10, -12 ]), -28); console.log( sumArray([ -6, 20, -1, 10, -12 ]) , 3 );