Last active
May 31, 2017 16:50
-
-
Save wende/9cef083b2d3964f46c6520441ffb56bb to your computer and use it in GitHub Desktop.
Elmchemy article #2
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
module FizzBuzz exposing (fizzbuzz) | |
import List exposing (map, range) | |
{-| Fizzes the buzzes and buzzfizzes the fizz out of buzz | |
fizzbuzz 1 7 == "1 2 Fizz 4 Buzz Fizz 7" | |
-} | |
fizzbuzz : Int -> Int -> String | |
fizzbuzz from to = | |
let fizzBuzz n = case (n % 3, n % 5) of | |
(0, 0) -> "FizzBuzz" | |
(0, _) -> "Fizz" | |
(_, 0) -> "Buzz" | |
_ -> toString n | |
in List.range from to |> map (fizzBuzz >> toString) |> joinWords | |
joinWords : List String -> String | |
joinWords list = String.join " " list |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment