Files
30-seconds-of-code/test/factorial/factorial.js
2018-01-17 13:40:40 -05:00

7 lines
167 B
JavaScript

const factorial = n =>
n < 0
? (() => {
throw new TypeError('Negative numbers are not allowed!');
})()
: n <= 1 ? 1 : n * factorial(n - 1);
module.exports = factorial