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 回答