Skip to content

Instantly share code, notes, and snippets.

@knugie
Created January 10, 2015 17:11
Show Gist options
  • Save knugie/6b1d8a39c245369c9c2f to your computer and use it in GitHub Desktop.
Save knugie/6b1d8a39c245369c9c2f to your computer and use it in GitHub Desktop.
ruby sort quiz question
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