Search
 
SCRIPT & CODE EXAMPLE
 

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]]
Comment

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]}
Comment

PREVIOUS NEXT
Code Example
Ruby :: rails form_tag 
Ruby :: find a key in nested hash ruby 
Ruby :: autoload lib directory rails 
Ruby :: ruby square root 
Ruby :: rails array sort 
Ruby :: ruby test is number 
Ruby :: rails scopes 
Ruby :: symbol to string ruby 
Ruby :: Rails.root 
Ruby :: call a class method ruby 
Ruby :: ruby each do method 
Ruby :: ruby on rails validates presence of multiple fields 
Ruby :: ruby array randomly display 
Ruby :: rails 10 times do 
Ruby :: ruby while loop 
Ruby :: grails 3 cron jobs 
Ruby :: CSV total rows ruby 
Ruby :: ruby shorthand if 
Ruby :: how to remove last element from array in ruby 
Ruby :: rails generate model with options 
Ruby :: sequel ruby alias table 
Ruby :: ruby nth element of array 
Ruby :: how to access function defined in model rails 
Ruby :: cant find user without id error in rails 
Ruby :: after_create for STI rails 
Ruby :: Missing template clients/show with {:locale=[:en], :formats=[:pdf], 
Ruby :: replace strring by another string ruby 
R :: automatically wrap r text label ggplot 
R :: defulat function values R 
R :: how to title plot in r 
ADD CONTENT
Topic
Content
Source link
Name
8+7 =