I'm trying to separate an array of integers to count how many repeated numbers are there.
For this input [10, 20, 20, 10, 10, 30, 50, 10, 20]
I am receiving the following output:
#{10=>"\n\n\n\n",20=>[20,20],30=>[30],50=>"2"}
Question
I would like to know how can I generate the following output
#{10=>[10,10,10,10],20=>[20,20],30=>[30],50=>[50]}
The function I am using to generate the map output is:
%% Next: number
%% Acc: map
separate_socks(Next, Acc) ->
KeyExists = maps:is_key(Next, Acc),
case KeyExists of
true ->
CurrentKeyList = maps:get(Next, Acc),
maps:update(Next, [Next | CurrentKeyList], Acc);
false -> maps:put(Next, [Next], Acc)
end.