Ad
  • Custom User Avatar

    oh yea stupid me. thanks a lot!

  • Custom User Avatar

    i have the same issue. empty array should be filtered out in if statement but it give error
    "TypeError: Reduce of empty array with no initial value at Array.reduce at sumArray"
    Anyone can help? code as follow:

    function sumArray(array) {
      if (!array || array.length <2 ) {
        return 0;
      } else {
       return array.sort(function (a,b) {return b-a}).slice(1,-1).reduce(function (a,b) {return a+b});
      }
    }