elm/exercises/allergies/Allergies.example.elm

31 lines
557 B
Elm
Raw Normal View History

module Allergies exposing (..)
2016-03-27 01:08:15 +00:00
import List
import Bitwise
isAllergicTo : String -> Int -> Bool
isAllergicTo name score =
List.member name (toList score)
2016-03-27 01:08:15 +00:00
toList : Int -> List String
toList score =
allergies
2016-12-17 22:15:34 +00:00
|> List.indexedMap (\i n -> ( Bitwise.shiftLeftBy i 1, n ))
|> List.filter (\( s, n ) -> Bitwise.and s score > 0)
2016-12-17 22:15:34 +00:00
|> List.map Tuple.second
2016-03-27 01:08:15 +00:00
allergies : List String
allergies =
[ "eggs"
, "peanuts"
, "shellfish"
, "strawberries"
, "tomatoes"
, "chocolate"
, "pollen"
, "cats"
]