항상 좋아하는 기능적 접근 방식 :
require 'pp'
a = [ {:foo => "aa","col" => "bar"}, { "lat" => 123, "lon" => 456 },
{ "lat" => 789, "lon" => 102, "col" => "red" },
{ "lat" => 442, "lon" => 342 } ]
arr = a.group_by{|h| h.key?("col")}
pp arr[false] + arr[true] # on the bottom
출력 :
[{"lat"=>123, "lon"=>456},
{"lat"=>442, "lon"=>342},
{:foo=>"aa", "col"=>"bar"},
{"lat"=>789, "lon"=>102, "col"=>"red"}]
pp arr[true] + arr[false] #on the top
출력 :
[{:foo=>"aa", "col"=>"bar"},
{"lat"=>789, "lon"=>102, "col"=>"red"},
{"lat"=>123, "lon"=>456},
{"lat"=>442, "lon"=>342}]
상단 또는 하단; 어느? – sawa
작성한 코드는 무엇입니까? –