KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have an array of objects [<#a star=1 val=1>, <#a star=nil val=3> , <#a star=2 val=2>] i need the array to be sorted by time, then by val [ <#a star=2 val=2>, <#a star=1 val=1>, <#a star=nil val=3> ] but using the sort_by throws an error because the time is nil. I am using an ugly way to sort right now, but i am sure there is a nice way to go about it starred=[] @answers.each {|a| (starred << a) if a.starred } @answers=@answers-starred starred=starred.sort_by {|a| a.starred }.reverse @answers=starred+@answers
Tags (comma-separated)
Save Edits
Cancel