Created
March 14, 2014 15:10
-
-
Save cheeyeo/9549588 to your computer and use it in GitHub Desktop.
Example of FizzBuzz in Ruby using procs
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
MULTIPLE_OF_3 = ->(n){ (n % 3).zero? } | |
MULTIPLE_OF_5 = ->(n){ (n % 5).zero? } | |
MULTIPLE_OF_3_AND_5 = ->(n){ MULTIPLE_OF_3[n] && MULTIPLE_OF_5[n] } | |
(1..100).each do |num| | |
case num | |
when MULTIPLE_OF_3_AND_5 | |
puts "FizzBuzz" | |
when MULTIPLE_OF_3 | |
puts "Fizz" | |
when MULTIPLE_OF_5 | |
puts "Buzz" | |
else | |
puts num.to_s | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment