Skip to content

Instantly share code, notes, and snippets.

@hanachin
Last active June 4, 2018 13:05
Show Gist options
  • Save hanachin/b82fd6e2ed556ace26dc8627b7387300 to your computer and use it in GitHub Desktop.
Save hanachin/b82fd6e2ed556ace26dc8627b7387300 to your computer and use it in GitHub Desktop.
継続渡しスタイル(loopは大目にみて...
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