You should probably try the code you're providing as a solution. That
cuts down on the stuff that a) raises exceptions, and b) doesn't solve
the problem even when the exceptions are gone.
···
On Nov 1, 11:34 pm, Isaac Sanders <isaacbfsand...@gmail.com> wrote:
Errr, yah. I almost had it there. sry, I was doing calc hw, and saw the
message, the thought didn't process....
···
On Tue, Nov 1, 2011 at 11:49 PM, Yossef Mendelssohn <ymendel@pobox.com>wrote:
On Nov 1, 11:34 pm, Isaac Sanders <isaacbfsand...@gmail.com> wrote:
> http://www.ruby-doc.org/core-1.9.2/Array.html#method-i-sort
>
> arr.sort do |x,y|
> if x.length < y.length
> return 1
> elsif x.length > y.length
> return -1
> else
> x <=> y
> end
> end
You should probably try the code you're providing as a solution. That
cuts down on the stuff that a) raises exceptions, and b) doesn't solve
the problem even when the exceptions are gone.
--
-yossef
--
Sincerely,
Isaac Sanders
Section C-4B Vice Chief, Order of the Arrow
Vice Chief of Administration, Tecumseh #65
Eagle Scout
In case you find the temporary structure created for sorting inelegant
you can do this:
irb(main):006:0* a = %w{A AA AB AF B C}
=> ["A", "AA", "AB", "AF", "B", "C"]
irb(main):007:0> a.sort {|x,y| (x.length <=> y.length).nonzero? or x <=> y}
=> ["A", "B", "C", "AA", "AB", "AF"]
Kind regards
robert
···
On Wed, Nov 2, 2011 at 12:28 PM, Sam Rose <samwho@lbak.co.uk> wrote:
On Nov 1, 2011, at 10:28 PM, Jan wrote:
array.sort_by {|s| [s.size, s]}
That's an incredibly elegant solution, thanks for sharing!