function - factorial in javascript without looping -
this question has answer here:
how factorial works without while or loop cant understand please explain
function factorial(x) { if (x === 0) { return 1; } return x * factorial(x - 1); } console.log(factorial(5));
it uses recursive function. factorial
calls many times, long x not 0.
Comments
Post a Comment