elm/exercises/allergies/Allergies.example.elm
2016-12-17 17:29:40 -05:00

30 lines
557 B
Elm

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