Sha256: 8c7f3dac76410188962377698f194288e82ff947dd9fe809e66db11eb1f07f5e

Contents?: true

Size: 484 Bytes

Versions: 131

Compression:

Stored size: 484 Bytes

Contents

defmodule Allergies do
  import Bitwise

  @allergens [
    "eggs",
    "peanuts",
    "shellfish",
    "strawberries",
    "tomatoes",
    "chocolate",
    "pollen",
    "cats"
  ]

  def list(flags) do
    Enum.with_index(@allergens)
    |> Enum.filter(&flagged?(flags, &1))
    |> Enum.map(fn {item, _} -> item end)
  end

  def allergic_to?(flags, item) do
    Enum.member?(list(flags), item)
  end

  defp flagged?(flags, {_, index}) do
    (flags &&& 1 <<< index) > 0
  end
end

Version data entries

131 entries across 131 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/elixir/exercises/allergies/example.exs
trackler-2.2.1.179 tracks/elixir/exercises/allergies/example.exs
trackler-2.2.1.178 tracks/elixir/exercises/allergies/example.exs
trackler-2.2.1.177 tracks/elixir/exercises/allergies/example.exs
trackler-2.2.1.176 tracks/elixir/exercises/allergies/example.exs
trackler-2.2.1.175 tracks/elixir/exercises/allergies/example.exs
trackler-2.2.1.174 tracks/elixir/exercises/allergies/example.exs
trackler-2.2.1.173 tracks/elixir/exercises/allergies/example.exs
trackler-2.2.1.172 tracks/elixir/exercises/allergies/example.exs
trackler-2.2.1.171 tracks/elixir/exercises/allergies/example.exs
trackler-2.2.1.170 tracks/elixir/exercises/allergies/example.exs
trackler-2.2.1.169 tracks/elixir/exercises/allergies/example.exs
trackler-2.2.1.167 tracks/elixir/exercises/allergies/example.exs
trackler-2.2.1.166 tracks/elixir/exercises/allergies/example.exs
trackler-2.2.1.165 tracks/elixir/exercises/allergies/example.exs
trackler-2.2.1.164 tracks/elixir/exercises/allergies/example.exs
trackler-2.2.1.163 tracks/elixir/exercises/allergies/example.exs
trackler-2.2.1.162 tracks/elixir/exercises/allergies/example.exs
trackler-2.2.1.161 tracks/elixir/exercises/allergies/example.exs
trackler-2.2.1.160 tracks/elixir/exercises/allergies/example.exs