1
I’m new to Elixir and I don’t understand the return of function.
list = %{"100" => 1, "50" => 2, "20" => 4, "10" => 8, "5" => 16, "1" => 32}
for {key, value} <- list, do: String.to_integer(key) * value
Or
Enum.map(list, fn({key, value}) -> String.to_integer(key) * value end)
Returns
' PdPPd'
But when I convert to String
for {key, value} <- list, do: "#{String.to_integer(key) * value}"
Returns
["32", "80", "100", "80", "80", "100"]
Do you want to keep order or do you want something functional? The result came out as expected, since the order is not mandatory to follow in this construction.
– Jefferson Quesado