Skip to content

Instantly share code, notes, and snippets.

@Lysak
Last active April 18, 2026 10:29
Show Gist options
  • Select an option

  • Save Lysak/0b159f190ebfc6fb83c5607a05579789 to your computer and use it in GitHub Desktop.

Select an option

Save Lysak/0b159f190ebfc6fb83c5607a05579789 to your computer and use it in GitHub Desktop.
fizzbuzz.js and fizzbuzz.php implementations
for (let i = 1; i <= 30; i++) {
const fizz = !(i % 3);
const buzz = !(i % 5);
if (fizz && buzz) console.log("FizzBuzz");
else if (fizz) console.log("Fizz");
else if (buzz) console.log("Buzz");
else console.log(i);
}
@Lysak
Copy link
Copy Markdown
Author

Lysak commented Apr 18, 2026

<?php

function fizzBuzzLabel(int $number): string
{
    $result = '';
    
    $fizz = $number % 3 === 0;
    $buzz = $number % 5 === 0;

    if ($fizz) {
        $result .= 'Fizz';
    }
    
    if ($buzz) {
        $result .= 'Buzz';
    }

    if ($result !== '') {
        return $result;
    }

    return (string) $number;
}

function getFizzBuzzList(int $start, int $end): Generator
{
//    $result = [];
    
    for ($i = $start; $i <= $end; $i++) {
        yield fizzBuzzLabel($i);
//        $result[] = fizzBuzzLabel($i);

    }
    
//    return $result;
}

function readLines(iterable $lines): void
{
    foreach ($lines as $line) {
        echo $line . PHP_EOL;
    }
}

readLines(getFizzBuzzList(1, 10_000_000));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment