-
-
Save mjs2600/4d8b5cecdc940bec2f7fc9cb1052dfc6 to your computer and use it in GitHub Desktop.
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
defmodule Fizzbuzz do | |
def parse(range \\ 1..100) do | |
range | |
|> Enum.map(&parse_num/1) | |
|> Enum.join | |
end | |
defp parse_num(n) do | |
fizzbuzzer(n, rem(n, 3), rem(n, 5)) | |
end | |
defp fizzbuzzer(_, 0, 0), do: "FizzBuzz" | |
defp fizzbuzzer(_, 0, _), do: "Fizz" | |
defp fizzbuzzer(_, _, 0), do: "Buzz" | |
defp fizzbuzzer(n, _, _), do: Integer.to_string(n) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment