Skip to content

Instantly share code, notes, and snippets.

@kurogelee
Last active July 30, 2018 20:08
Show Gist options
  • Save kurogelee/f0dd1bb7320cb365a17ae28dcdcef4c8 to your computer and use it in GitHub Desktop.
Save kurogelee/f0dd1bb7320cb365a17ae28dcdcef4c8 to your computer and use it in GitHub Desktop.
TypeScriptでFizzBuzz(generator, destructuringなどして) ref: https://qiita.com/kurogelee/items/d9451bc429e12b6f3d5c
class Fizz {
public static spec: Array<[number, string]> = [[15, "FizzBuzz"], [5, "Buzz"], [3, "Fizz"]];
public static *buzz(size: number) {
for (const i of Array(size).keys()) {
const [_, result] = Fizz.spec.find(([n, s]) => i % n === 0) || [0, i.toString()];
yield result;
}
}
}
Array.from(Fizz.buzz(20)).forEach((i) => console.log(i));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment