How do I sort this:
arr = ["aaa","aa","aaaa","a","aaaaa"];
into this
arr = ["a","aa","aaa","aaaa","aaaaa"];
How do I sort this:
arr = ["aaa","aa","aaaa","a","aaaaa"];
into this
arr = ["a","aa","aaa","aaaa","aaaaa"];
arr = arr.sort_by {|x| x.length}
Or in 1.8.7+:
arr = arr.sort_by(&:length)