Created
October 27, 2015 19:41
-
-
Save irfansharif/36cdc2ec4f2ff2b5f5ca to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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