Ruslan Ulanov’s Codeshack

The developer’s notebook

Factorial

leave a comment

A function that calculates a number’s factorial using recursion.

function factorial(n) {
    return n * ((n > 1) ? factorial(n - 1) : 1);
}

Written by Ruslan Ulanov

October 15th, 2013 at 1:02 am

Posted in JavaScript