Created
May 27, 2024 16:04
-
-
Save selfsigned/31a760e5fe4cdbb7274359f5a77609d6 to your computer and use it in GitHub Desktop.
Functional FizzBuzz
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
// Logic | |
type FizzBuzzOutput = (x: number) => string | |
const Fizz : FizzBuzzOutput = x => (x % 3 === 0) ? "Fizz" : "" | |
const Buzz : FizzBuzzOutput = x => (x % 5 === 0) ? "Buzz" : "" | |
const FizzBuzzPrint : FizzBuzzOutput = x => Fizz(x) + Buzz(x) | |
type FizzBuzz = (x: number) => Array<string> | |
const FizzBuzz : FizzBuzz = x => x < 1 ? [] : [...FizzBuzz(x-1), FizzBuzzPrint(x)] | |
// Execution | |
console.log(FizzBuzz(100)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment