RosettaCodeData/Task/Search-a-list/Elixir/search-a-list.elixir

8 lines
280 B
Plaintext

haystack = ~w(Zig Zag Wally Ronald Bush Krusty Charlie Bush Bozo)
Enum.each(~w(Bush Washington), fn needle ->
index = Enum.find_index(haystack, fn x -> x==needle end)
if index, do: (IO.puts "#{index} #{needle}"),
else: raise "#{needle} is not in haystack\n"
end)