mirror of
https://github.moeyy.xyz/https://github.com/trekhleb/javascript-algorithms.git
synced 2024-09-20 07:43:04 +08:00
Update factorial.js
updated the factorial program to work with Negative Numbers also.
This commit is contained in:
parent
76617fa83a
commit
8c9bce0940
@ -3,6 +3,10 @@
|
||||
* @return {number}
|
||||
*/
|
||||
export default function factorial(number) {
|
||||
//resulting to a negative number
|
||||
if(number<0)
|
||||
return NaN;
|
||||
|
||||
let result = 1;
|
||||
|
||||
for (let i = 2; i <= number; i += 1) {
|
||||
|
Loading…
Reference in New Issue
Block a user