Search
 
SCRIPT & CODE EXAMPLE
 

RUBY

sort numbers in ascending order ruby

result = [41, 9, -9, 2, 31, 32, 12, -1]

result = result.sort { |a, b| a <=> b }

puts result

#OUTPUT: 
-9
-1
2
9
12
31
32
41
Comment

ruby sort array numerically

a.sort_by(&:to_i)
Comment

ruby sort array numerically

a = ["teste", "test", "teste2", "tes3te", "10teste"]
a.sort_by! {|s| s[/d+/].to_i}
Comment

PREVIOUS NEXT
Code Example
Ruby :: singleton class in ruby 
Ruby :: rails render partial 
Ruby :: rails undo generate model 
Ruby :: ruby 
Ruby :: rails route list 
Ruby :: save to csv ruby 
Ruby :: rails convert image to base64 
Ruby :: rails convert unix timestamp to datetime 
Ruby :: capitalize composed name ruby 
Ruby :: render partial rails 
Ruby :: rails params require check exists 
Ruby :: font awesome icon rails submit button 
Ruby :: ruby array shift 
Ruby :: force user to login before action devise rails 
Ruby :: .delete ruby 
Ruby :: ruby check if hash has method before calling it 
Ruby :: infinite loop in ruby 
Ruby :: get single hash key ruby 
Ruby :: insert element in the middle of an array ruby 
Ruby :: intermediate rails project 
Ruby :: ruby null 
Ruby :: rails scope alias 
Ruby :: irb loaderror 
Ruby :: how to use action_view in console rails 
Ruby :: rails activerecord saved_change_to 
R :: add a vertical line in ggplot 
R :: WARNING: Rtools is required to build R packages but is not currently installed. Please download and install the appropriate version of Rtools before proceeding: 
R :: r read all files in folder 
R :: rmarkdown put date 
R :: r - extracting specific columns from a data frame 
ADD CONTENT
Topic
Content
Source link
Name
3+1 =