re: Daily Coding Puzzles - Nov 4th - Nov 9th VIEW POST

TOP OF THREAD FULL DISCUSSION
re: Tuesday Product of Array Items (7 KYU): Calculate the product of all elements in an array. CodeWars
 

I decided to not use reduce so that I could return early if I hit a zero.

function product(values) {
  if(!values || values.length === 0) return null;
  let prod = values[0];
  for(let i=1; i<values.length; i++) {
    if(values[i] === 0) return 0;
    prod *= values[i];
  }
  return result;
}
code of conduct - report abuse