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.159 tracks/elixir/exercises/allergies/example.exs
trackler-2.2.1.158 tracks/elixir/exercises/allergies/example.exs
trackler-2.2.1.157 tracks/elixir/exercises/allergies/example.exs
trackler-2.2.1.156 tracks/elixir/exercises/allergies/example.exs
trackler-2.2.1.155 tracks/elixir/exercises/allergies/example.exs
trackler-2.2.1.154 tracks/elixir/exercises/allergies/example.exs
trackler-2.2.1.153 tracks/elixir/exercises/allergies/example.exs
trackler-2.2.1.152 tracks/elixir/exercises/allergies/example.exs
trackler-2.2.1.151 tracks/elixir/exercises/allergies/example.exs
trackler-2.2.1.150 tracks/elixir/exercises/allergies/example.exs
trackler-2.2.1.149 tracks/elixir/exercises/allergies/example.exs
trackler-2.2.1.148 tracks/elixir/exercises/allergies/example.exs
trackler-2.2.1.147 tracks/elixir/exercises/allergies/example.exs
trackler-2.2.1.146 tracks/elixir/exercises/allergies/example.exs
trackler-2.2.1.145 tracks/elixir/exercises/allergies/example.exs
trackler-2.2.1.144 tracks/elixir/exercises/allergies/example.exs
trackler-2.2.1.143 tracks/elixir/exercises/allergies/example.exs
trackler-2.2.1.142 tracks/elixir/exercises/allergies/example.exs
trackler-2.2.1.141 tracks/elixir/exercises/allergies/example.exs
trackler-2.2.1.140 tracks/elixir/exercises/allergies/example.exs