Is there any way to use sort_by
and make nil
s appear in the front.
For example
[-1, 2, 3, nil, nil].sort_by &some_block
should give
#=> [nil, nil, -1, 2, 3]
It's similar to this question but the solution there does not work with negative values.