RosettaCodeData/Task/Search-a-list/Elixir/search-a-list.elixir
2015-11-18 06:14:39 +00:00

7 lines
280 B
Text

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)