Last active
June 4, 2018 13:05
-
-
Save hanachin/b82fd6e2ed556ace26dc8627b7387300 to your computer and use it in GitHub Desktop.
継続渡しスタイル(loopは大目にみて...
This file contains 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
function fizz(n, cont) { | |
if (n % 3 == 0) { | |
cont("Fizz"); | |
} else { | |
cont(); | |
} | |
} | |
function buzz(n, cont) { | |
if (n % 5 == 0) { | |
cont("Buzz"); | |
} else { | |
cont(); | |
} | |
} | |
function fizzbuzz(n, cont) { | |
fizz(n, (fizz) => buzz(n, (buzz) => fizz && buzz ? cont(fizz + buzz) : cont(fizz || buzz || n))); | |
} | |
function loop(b, e, f) { | |
if (b <= e) { | |
f(b); | |
loop(b + 1, e, f); | |
} | |
} | |
loop(1, 100, (n) => fizzbuzz(n, (ret) => console.log(ret))); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment