I have to check and select the latest one from the array of hashes. The structure is like this:
'histories':[
{
{
...
},
'created': "date1",
'items':[
{
'a': "Ready",
'b': "dfknsknfs",
},
{
'a': "sdfjbsf",
'b': "hello23",
}
]
},
{
{
...
},
'created': "date2",
'items':[
{
'a': "sknfkssd",
'b': "ksdfjshs",
},
{
'a': "Ready",
'b': "shdfjsh",
}
]
},
...
]
I have to first find for the value "Ready" and then i have to select the latest "created" date.
My attempt for this is like
ready_item = histories.select { |item| item.items.detect {|f| f.a == "Ready" } }
ready_item
But since the detect
is used, it is returning only the first detected value. But i need to get the latest date. What should be the possible solution of it?