Files
30-seconds-of-code/test/factorial/factorial.js
2018-08-02 13:49:33 +03:00

10 lines
204 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;