mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2026-03-13 15:21:15 +08:00
chore: check for invalid input to factorial (#1229)
This commit is contained in:
committed by
GitHub
parent
d9d085faa7
commit
5364a1c31b
@@ -9,6 +9,14 @@
|
||||
*/
|
||||
|
||||
const factorial = (n) => {
|
||||
if (!Number.isInteger(n)) {
|
||||
throw new RangeError('Not a Whole Number')
|
||||
}
|
||||
|
||||
if (n < 0) {
|
||||
throw new RangeError('Not a Positive Number')
|
||||
}
|
||||
|
||||
if (n === 0) {
|
||||
return 1
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user