Open In App

Ruby | Array min() function

Improve
Improve
Like Article
Like
Save
Share
Report

Array#min() : min() is a Array class method which returns the minimum value in this array.

Syntax: Array.min()

Parameter: Array

Return: the minimum value in this array.

Example #1 :




# Ruby code for min() method
  
# declaring array
a = %w[for geeks]
  
  
# min method example
puts "min() method form : #{a.min()}\n\n"
  
puts "min() method form : #{a.min(2)}\n\n"


Output :

min() method form : for

min() method form : ["for", "geeks"]

Example #2 :




# Ruby code for min() method
  
# declaring array
a = %w[hi I can code for geeks]
  
  
# min method example
puts "min() method form : #{a.min(4)}\n\n"
  
puts "min() method form : #{a.min(1)}\n\n"


Output :

min() method form : ["I", "can", "code", "for"]

min() method form : ["I"]

Last Updated : 06 Dec, 2019
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads