array_reduce.js 276 B

123456789
  1. const arr = ["0", 5, 3, "string", null];
  2. const sum = params => {
  3. const multiply = (previousValue, currentValue) => (typeof currentValue === 'number' ? previousValue * currentValue : previousValue);
  4. return params.reduce(multiply, 1);
  5. }
  6. console.log(sum(arr)); // 15