Skip to content

Instantly share code, notes, and snippets.

@yoavrubin
yoavrubin / factorial.js
Created December 12, 2013 20:56
A trip down factorial lane - see what Javascript functions and some functional programming goodies can do
// the most basic factorial
function fact1(n){
if(n < 2) return 1;
return n*fact1(n-1);
}
// let's add some precondition verifications
function fact2(n){
if(typeof n !== 'number' || isNaN(n) || n < 0)