Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@irfansharif
Created October 27, 2015 19:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save irfansharif/36cdc2ec4f2ff2b5f5ca to your computer and use it in GitHub Desktop.
Save irfansharif/36cdc2ec4f2ff2b5f5ca to your computer and use it in GitHub Desktop.
var add_one = function ( n ) {
return n + 1;
}
var subtract_one = function ( n ) {
return n - 1;
}
var sum = function ( a, b ) {
if (b === 0) {
return a;
} else {
return sum( add_one( a ), subtract_one ( b ) );
};
}
var product = function( a, b ) {
if ( b == 1 ) {
return a;
} else {
return sum( a, product( a, subtract_one(b) ) );
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment