Last active
August 29, 2015 14:16
-
-
Save yoshikischmitz/f0a768d2e6239dc7d710 to your computer and use it in GitHub Desktop.
A highly extensible, declarative fizzbuzz with no hardcoded if statements, and no mutation.
This file contains hidden or 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
applicators = {3 => "fizz", 5 => "buzz"} | |
fizzbuzz = | |
(1..100).map do |n| | |
fb = applicators. | |
select{|a| n % a == 0}. | |
values.join | |
[n.to_s, fb].max # "1" > "" and "fizz" > "100000" since "1" < "a" | |
end | |
puts fizzbuzz |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here is my attempt at the same thing. Self is a fizzbuzz module - I have a variety of solution attempts...