Skip to content

Instantly share code, notes, and snippets.

@dpoindexter
Last active December 10, 2015 05:48
Show Gist options
  • Save dpoindexter/4389626 to your computer and use it in GitHub Desktop.
Save dpoindexter/4389626 to your computer and use it in GitHub Desktop.
Extensible Fizbuzz, based on monoids
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