I'm trying to implement a dictionary but the Map.put function is not adding the new element to the map instead it is giving me a new map with the last (key, value} inserted I also tried Map.put_new it did not work
def someFunction(array) do
dict = %{}
Enum.each(array, fn item ->
if (Map.has_key?(dict, item)) do
dict = %{dict | item => (dict[item] + 1)}
else
dict = Map.put(dict , item, 1)
end
end)
end