elixir的小作业demo
# a = %{
# "mami" => ["a", "d"],
# "star" => ["c", "b"]}
# b = %{"a" => "1",
# "b" => ["2","3","4"],
# "c" => ["5","6"],
# "d" => ["7","8"] }
# (思路: 从第一个的a ["a","b","c","d"] 中,遍历取 到b中看是否是b
# 中的key,若是,则变成map %{}, 插入到a的位置中 )
# 变成=>
# c = %{
# "mami" => [ %{"a" => "1"}, %{"d" => ["7","8"]}],
# "star" => [ %{"c" => ["5","6"]}, %{"b" => ["2","3","4"]}]
# }
# # c = %{
# # "mami" => [ %{"a" => "1"}],
# # "star" => [ %{"c" => ["5","6"]}]
# # }
# # c1 = %{
# # "mami" => [ %{"d" => ["7","8"]}],
# # "star" => [ %{"b" => ["2","3","4"]}]
# # }
# cc1 = Enum.map(["c","d"], fn(x) -> %{"star" => [%{x => Map.get(b,x)}]} end)
# Enum.reduce(cc1, %{}, fn m, acc ->
# Map.merge(acc, m, fn
# _k, v1, v2 when is_list(v1) ->
# :lists.reverse([v2 | :lists.reverse(v1)])
# _k, v1, v2 -> [v1, v2]
# end)
# end)