I have an array of hashes which I have to sort based on four different key value pairs.
Here is the array of hashes, I want First I want to sort based on "to" then based on "from"
[
{
:title=>"Working as a SSE",
:organisation=>{:id=>428, :name=>"google"},
:from=>"2018-6-1",
:to=>nil
}, {
:title=>"Concatenate two video files to single video in players",
:organisation=>{:id=>197, :name=>"UNFPA"},
:from=>"2014-1-1",
:to=>"2015-12-1"
}, {
:title=>"Highcharts Demo",
:organisation=>{:id=>6, :name=>"UNDFS"},
:from=>"2016-1-1",
:to=>"2017-6-1"
}, {
:title=>"Working as a Judicial Affairs",
:organisation=>{:id=>427, :name=>"swtp"},
:from=>"2017-1-1",
:to=>"2018-6-1"
}
]
I want the sorting should happen in the following order
- First sort is based on "to"
- Second sort is based on "from"
- Third sort is based on "organisation name"
- Finally, sort based on "title"
Can anyone help me sort the array of hashes?
Aucun commentaire:
Enregistrer un commentaire