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]]
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]]
sort array of hashes ruby
classes = [{
start_date_time: Wed, 07 Jul 2021 12:52:20 +0000
}]
sorted_classes = classes.sort_by {|sc| sc[:start_date_time]}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us