Skip to content

Instantly share code, notes, and snippets.

@uhyo
Last active October 16, 2019 09:14
Show Gist options
  • Save uhyo/9ddc3a588068d3595252be3a284ed119 to your computer and use it in GitHub Desktop.
Save uhyo/9ddc3a588068d3595252be3a284ed119 to your computer and use it in GitHub Desktop.
fizzbuzz.js
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();
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