How can I sort an array like the one below :
[["9213533",
{:length=>"9213533",
:units=>["Meters", "Feet", "Yards"],
:frequency=>3}],
[nil,
{:length=>nil, :units=>["Feet"], :frequency=>1}],
["5951975",
{:length=>"5951975", :units=>["Yards"], :frequency=>1}],
["9100799",
{:length=>"9100799", :units=>["Feet"], :frequency=>1}]]
I'd like to sort it so the first element of arrays array who is nil comes to the last place like this (sorted) :
[["9213533",
{:length=>"9213533",
:units=>["Meters", "Feet", "Yards"],
:frequency=>3}],
["5951975",
{:length=>"5951975", :units=>["Yards"], :frequency=>1}],
["9100799",
{:length=>"9100799", :units=>["Feet"], :frequency=>1}]],
[nil,
{:length=>nil, :units=>["Feet"], :frequency=>1}]
I've tried with sort by method (arr is my array):
arr.sort_by{|a,b| b[:length] unless a.nil?}
Got this exception :
ArgumentError: comparison of NilClass with String failed
from (pry):395:in `sort_by