JavaScript czynnikowy
// Simple arrow function solution
var factorial = n => (n <= 0) ? 1: n * factorial(n - 1);
juliocorradi
// Simple arrow function solution
var factorial = n => (n <= 0) ? 1: n * factorial(n - 1);
let myArray = [];
function calculateFactorial (myFacNumber)
{
let result = 1;
let c;
for(let x = 1; x<=myFacNumber; x++)
{
for(let j = x; j<=x;j++)
{
c= myArray[j] = x;
result *= c;
}
}
return result;
}
console.log(calculateFactorial(5));
let factorial = n=>Array(n).fill(0).map((v,i)=>i+1).reduce((a,b)=>a*b) //oneline
function factorialMl(n) {
return Array(n).fill(0).map(function(v,i){
return i+1
}).reduce(function(a,b){
return a*b
})
}