Created
February 7, 2020 01:01
-
-
Save gr33n7007h/e698b9da402f69d1bd1c2c8be14c920c to your computer and use it in GitHub Desktop.
FizzBuzz using Ruby 2.7 pattern matching.
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
#!/usr/bin/env ruby | |
fizzbuzz = -> (n) { | |
case [n % 3, n % 5, n] | |
in 0, 0, _; "FizzBuzz" | |
in 0, _, _; "Fizz" | |
in _, 0, _; "Buzz" | |
else n | |
end | |
} | |
puts (1..100).map &fizzbuzz |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment