Last active
October 16, 2019 09:14
-
-
Save uhyo/9ddc3a588068d3595252be3a284ed119 to your computer and use it in GitHub Desktop.
fizzbuzz.js
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
let fizzbuzz = false; | |
function* range() { | |
for (let i=1; i<=100; i++) yield i; | |
} | |
async function fizz() { | |
for (const i of range()) { | |
if (i % 3 === 0) { | |
fizzbuzz=true; | |
process.stdout.write("Fizz"); | |
} | |
await null; | |
} | |
} | |
async function buzz() { | |
for (const i of range()) { | |
if (i % 5 === 0) { | |
fizzbuzz=true; | |
process.stdout.write("Buzz"); | |
} | |
await null; | |
} | |
} | |
async function num() { | |
for (const i of range()) { | |
if (!fizzbuzz) process.stdout.write(String(i)); | |
await null; | |
} | |
} | |
async function lf() { | |
for (const i of range()) { | |
process.stdout.write('\n'); | |
fizzbuzz = false; | |
await null; | |
} | |
} | |
fizz(); buzz(); num(); lf(); |
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
let fizzbuzz = false; | |
function* range() { | |
for (let i=1; i<=100; i++) yield i; | |
} | |
async function fizz() { | |
while (true) { | |
await null; | |
await null; | |
fizzbuzz=true; | |
process.stdout.write("Fizz"); | |
await null; | |
} | |
} | |
async function buzz() { | |
while (true) { | |
await null; | |
await null; | |
await null; | |
await null; | |
fizzbuzz=true; | |
process.stdout.write("Buzz"); | |
await null; | |
} | |
} | |
async function num() { | |
for (const i of range()) { | |
if (!fizzbuzz) process.stdout.write(String(i)); | |
await null; | |
} | |
} | |
async function lf() { | |
for (const i of range()) { | |
process.stdout.write('\n'); | |
fizzbuzz = false; | |
await null; | |
} | |
process.exit(0); | |
} | |
fizz(); buzz(); num(); lf(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment