Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def funny_sort(arr)
- parse = lambda {|str| str.scan(/\d+/).fetch(0, "-1").to_i }
- arr.sort {|x, y| parse.call(x) <=> parse.call(y) }
- end
- puts funny_sort(["abc", "123", "abc321", "213abc", "1.2", "a.3.2", "-987"])
- #=> ["abc", "1.2", "a.3.2", "123", "213abc", "abc321", "-987"]
- # key = -1, 1, 3, 123, 213, 321, 987
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement