Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR RUBY

sort hash ruby

people = {
  :fred => 23,
  :joan => 18,
  :pete => 54
}

# First option
people.values.sort    # => [18, 23, 54]

# Seconf option
people.sort_by { |name, age| age }
  # => [[:joan, 18], [:fred, 23], [:pete, 54]]
 
PREVIOUS NEXT
Tagged: #sort #hash #ruby
ADD COMMENT
Topic
Name
1+1 =