2

timestamp次のハッシュの配列から、最も高い値を持つ単一のハッシュを選択するにはどうすればよいですか?

data = [
  {"id" => 1, "timestamp" => 1383314276, "data" => "bea7c82f-f4b2-492a-aba3-033b1a54d9d0"},
  {"id" => 2, "timestamp" => 1383314386, "data" => "64ed2ed9-763d-443f-a74e-e7f10cbe783e"},
  {"id" => 3, "timestamp" => 1383314331, "data" => "f8cfaa99-ffe0-4d88-8fac-37e4ce462d3a"}
]
4

1 に答える 1

5

ここで見ることができます:

 data.max_by{|e| e["timestamp"] }
 # >> {"id"=>2, "timestamp"=>1383314386, "data"=>"64ed2ed9-763d-443f-a74e-e7f10cbe783e"}
于 2013-11-01T14:12:45.897 に答える