DEV Community

Discussion on: Daily Coding Puzzles - Nov 4th - Nov 9th

Collapse
 
clandau profile image
Courtney

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;
}