Is there a way to take multiple lists and get all the elements at their n th index and pass them to the function?
For example, list1 (= [1,3,5]) and list2 (= [2,4,6]) are added,then list (=[3,7,11]) is created.
What I wrote below is wrong, but I imagine such usage.
defmodule TwoLists do
def sum(list1,list2) do
Enum.map(list1,list2,fn(a,b)->a+b end)
end
end
iex> list1 = [1,3,5]
iex> list2 = [2,4,6]
iex> TwoLists.sum(list1,list2)
#-->Enum.map/3 is undefined error
I’d like you to show me the way to implement.
Thanks