FizzBuzz in Elixir
Here's the result of a recent junior dev coding dojo, tackling fizz buzz in a totally new language for us - elixir.
defmodule FIZZBUZZER do
def fizzbuzz(value) when rem(value, 15) == 0 do
"FizzBuzz"
end
def fizzbuzz(value) when rem(value, 3) == 0 do
"Fizz"
end
def fizzbuzz(value) when rem(value, 5) == 0 do
"Buzz"
end
def fizzbuzz(value) do
value
end
end
Everyone's minds were blown with the inside-out-ness of the solution, providing several different implementations with the matching code "outside" of the body of the function.
We ran the dojo using the wonderful cyber-dojo TDD tool (and forgot to change the name of the module away from the default Hitchhiker's Guide to the Galaxy naming convention).