Skip to content

Instantly share code, notes, and snippets.

@dreamr
Created September 19, 2011 20:23
Show Gist options
  • Save dreamr/1227504 to your computer and use it in GitHub Desktop.
Save dreamr/1227504 to your computer and use it in GitHub Desktop.
d=["2x4","2x6","4x4","4x10","2x8", "2x10"]
d.sort {|a,b| a.split("x") <=> b.split("x")} # doesnt work, nor any variations I can think of
# expected
["2x4","2x6","2x8","2x10","4x4", "4x10"]
@dreamr
Copy link
Author

dreamr commented Sep 19, 2011

d.sort {|a,b| a.split("x").map(&:to_i) <=> b.split("x").map(&:to_i)}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment