Skip to content

Instantly share code, notes, and snippets.

@SatoTakeshiX
Last active October 16, 2020 13:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SatoTakeshiX/0931a00b9a6fca05db9a58ee942e811d to your computer and use it in GitHub Desktop.
Save SatoTakeshiX/0931a00b9a6fca05db9a58ee942e811d to your computer and use it in GitHub Desktop.
merge
master_array = [[1, 2], [3, 4]]
remote_array = [{"id" => 12, "config" => [3, 4]}, {"id" => 533, "config" => [1, 2]}]
result_test = ["a", "b"] # master_arrayと同じindexでオブジェクトを作りたい。 { "config" : [1, 2], "id":"a"}
array_result = master_array.map.with_index { |item, index|
remote = remote_array.find {|i| item == i["config"]}
result = {
"result" => result_test[index],
"configs" => item,
"id" => remote["id"]
}
}
p array_result
@SatoTakeshiX
Copy link
Author

[{"result"=>"a", "configs"=>[1, 2], "id"=>533}, {"result"=>"b", "configs"=>[3, 4], "id"=>12}]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment