Last active
July 30, 2018 20:08
-
-
Save kurogelee/f0dd1bb7320cb365a17ae28dcdcef4c8 to your computer and use it in GitHub Desktop.
TypeScriptでFizzBuzz(generator, destructuringなどして) ref: https://qiita.com/kurogelee/items/d9451bc429e12b6f3d5c
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
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