Created
January 10, 2015 17:11
-
-
Save knugie/6b1d8a39c245369c9c2f to your computer and use it in GitHub Desktop.
ruby sort quiz question
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ary = [['a', :hello], ['b', :foo], ['b', :bar], ['b', :baz], ['a', :world]] | |
# QUIZ: | |
# How do you sort "ary" so equal objects stay in the same relative order to each other? | |
# "ary" should be sorted by the first element of each entry. | |
# Try now: http://tryruby.org/ | |
expected = [['a', :hello], ['a', :world], ['b', :foo], ['b', :bar], ['b', :baz]] | |
# HINT: | |
# ary.sort_by { |e| e[0] } is not the solution | |
# Here is a solution: https://gist.github.com/knugie/32ec406f6848baf67f21 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment