Created
February 11, 2014 04:39
-
-
Save goliatone/8929353 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 Test1 do | |
| def upto(n) when n > 0 do | |
| 1..n |> Enum.map(&fizzbuzz/1) | |
| end | |
| defp fizzbuzz(n) when rem(n, 3) == 0 and rem(n, 5) == 0, do: "FizzBuzz" | |
| defp fizzbuzz(n) when rem(n, 3) == 0, do: "Fizz" | |
| defp fizzbuzz(n) when rem(n, 5) == 0, do: "Buzz" | |
| defp fizzbuzz(n), do: n | |
| end | |
| defmodule Test2 do | |
| def upto(n) when n > 0 do | |
| 1..n |> Enum.map(&fizzbuzz/1) | |
| end | |
| defp fizzbuzz(n) do: | |
| cond do | |
| rem(n, 3) == 0 and rem(n, 5) == 0 -> | |
| "FizzBuzz" | |
| rem(n, 3) == 0 -> | |
| "Fizz" | |
| rem(n, 5) == 0 -> | |
| "Buzz" | |
| true -> | |
| n | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment