Skip to content

Instantly share code, notes, and snippets.

Yoav Rubin yoavrubin

View GitHub Profile
@yoavrubin
yoavrubin / factorial.js
Created Dec 12, 2013
A trip down factorial lane - see what Javascript functions and some functional programming goodies can do
View factorial.js
// 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)
You can’t perform that action at this time.