Hello peolpe,
simple question, I have these 2 maps
[{"Africa", 1}, {"America", 2}, {"Europe", 3}]
[{"Congo", 1, 1}, {"France", 2, 3}, {"Spain", 3, 3}, {"USA", 4, 2}, {"Egypt", 5, 1}]
I want to use Enum.map and Enum.filter to get below result
[
"Africa": [{"Congo", 1},{"Egypt", 1}],
"America": [{"USA", 4}],
"Europe": [{"France", 2}, {"Spain", 3}]
]
I have tried with the below combination but Im not getting the expected result. Can you give some help?
Enum.map(
[{"Africa", 1}, {"America", 2}, {"Europe", 3}],
fn {continent_name, continent_id} ->
Enum.filter(
[{"Congo", 1, 1},{"France", 2, 3},{"Spain", 3, 3},{"USA", 4, 2},{"Egypt", 5, 1}],
fn {country_name, country_id, country_continent_id} ->
if continent_id == country_continent_id do
[continent_name: [{country_name, country_id}]]
end
end)
end
)