Last active
December 10, 2015 05:48
-
-
Save dpoindexter/4389626 to your computer and use it in GitHub Desktop.
Extensible Fizbuzz, based on monoids
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
var printers = { | |
3: "Fizz", | |
5: "Buzz", | |
7: "Baz" | |
} | |
function forNumber(n) { | |
var print = ''; | |
for var printer in printers { | |
if (n % printer.Key === 0) print += printer.Value; | |
} | |
print = (print === '') ? print : n; | |
return print; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment