Update factorial.js

updated the factorial program to work with Negative Numbers also.
This commit is contained in:
Hemanth Kumar M 2024-01-27 23:03:33 +05:30 committed by GitHub
parent 76617fa83a
commit 8c9bce0940
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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) {