function factorialize(num) { return num < 0 ? 1 : new Array(num) .fill(undefined) .reduce((product, _, index) => product * (index + 1), 1); } factorialize(5);