Last active
September 25, 2021 09:00
-
-
Save Stefanacef/1b9f7c5648bba00f089ea0eac90630ab to your computer and use it in GitHub Desktop.
Factorialize a Number | Solution | JavaScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//For example: 5! = 1 * 2 * 3 * 4 * 5 = 120 | |
function factorialize(num) { | |
let numFac=[] ; | |
for(let i=1;i<=num;i++){ | |
if(numFac.indexOf(num[i])==-1){ | |
numFac.push(i); | |
} | |
} | |
return numFac.reduce((acc,val)=>{ | |
return acc=acc*val; | |
},1) | |
} | |
console.log(factorialize(5)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment