Last active
May 26, 2016 17:19
-
-
Save anthonylebrun/2c9c12432e3ef7029c9eb86fed58bc6f to your computer and use it in GitHub Desktop.
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
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