M
Mr_Tibs
Hi,
I have a [m X n] double-dimensional array in Ruby and I'm trying to
sort the entries (rows) by the 6-th column, which is a DateTime
object. Things get a little bit complicated, since I might have a nil
value in that column. If that happens, then I want to sort by the 7-th
column.
This is what I have so far:
cset_arr = cset_arr.sort do |x, y|
if x[5].nil? && y[5].nil?
x[6] <=> y[6]
elsif x[5].nil? && !y[5].nil?
y[5] # ???
elsif !x[5].nil? && y[5].nil?
x[5] # ???
elsif !x[5].nil? && !y[5].nil?
x[5] <=> y[5]
end
end
For the second and third if statements, I don't know how to "select"
that value. So, for example, if both 6-th columns are nil, then
compare by the 7-th column (first if). But, if the first record has a
nil 6-th column and the second record has a non-nil 6-th column, then
how do I set the second record as being the "selected" one of the two?
The current form (e.g. y[5]) does not work.
Thanks,
Tiberiu
I have a [m X n] double-dimensional array in Ruby and I'm trying to
sort the entries (rows) by the 6-th column, which is a DateTime
object. Things get a little bit complicated, since I might have a nil
value in that column. If that happens, then I want to sort by the 7-th
column.
This is what I have so far:
cset_arr = cset_arr.sort do |x, y|
if x[5].nil? && y[5].nil?
x[6] <=> y[6]
elsif x[5].nil? && !y[5].nil?
y[5] # ???
elsif !x[5].nil? && y[5].nil?
x[5] # ???
elsif !x[5].nil? && !y[5].nil?
x[5] <=> y[5]
end
end
For the second and third if statements, I don't know how to "select"
that value. So, for example, if both 6-th columns are nil, then
compare by the 7-th column (first if). But, if the first record has a
nil 6-th column and the second record has a non-nil 6-th column, then
how do I set the second record as being the "selected" one of the two?
The current form (e.g. y[5]) does not work.
Thanks,
Tiberiu