There's a lack of pattern matching and recursion in the comments, so here we go:
defmodule FizzBuzz do def run(0) do IO.puts("Finished") end def run(n) when is_integer(n) do n |> fizzbuzz(rem(n, 3), rem(n, 5)) |> run() end defp fizzbuzz(n, 0, 0) do IO.puts("#{n}: FizzBuzz") n - 1 end defp fizzbuzz(n, 0, _) do IO.puts("#{n}: Fizz") n - 1 end defp fizzbuzz(n, _, 0) do IO.puts("#{n}: Buzz") n - 1 end defp fizzbuzz(n, _, _) do IO.puts("#{n}") n - 1 end end
Nice, thanks for sharing this approach.
Rickard Laurin just posted another similar approach in ReasonML as well.
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
There's a lack of pattern matching and recursion in the comments, so here we go:
Nice, thanks for sharing this approach.
Rickard Laurin just posted another similar approach in ReasonML as well.