Created
November 24, 2011 12:01
-
-
Save shigeki/1391197 to your computer and use it in GitHub Desktop.
JavaScript で for/while 文を使わないで1から10までの合計を求める方法(process.netxtTick()を使わないnode-fibの真似編:実はこっちの方が速かった)
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 calc = function(n, callback) { | |
var sum = function(i, res) { | |
var func = (n>i) ? sum : function(j,k) {callback(k);}; | |
func(i+1, res+i); | |
}; | |
sum(1,0); | |
}; | |
calc(10, function(x) {console.log(x);}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment