Skip to content

Instantly share code, notes, and snippets.

@Stefanacef
Last active September 25, 2021 09:00
Show Gist options
  • Save Stefanacef/1b9f7c5648bba00f089ea0eac90630ab to your computer and use it in GitHub Desktop.
Save Stefanacef/1b9f7c5648bba00f089ea0eac90630ab to your computer and use it in GitHub Desktop.
Factorialize a Number | Solution | JavaScript
//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