📜  红宝石 |数组 min()函数

📅  最后修改于: 2022-05-13 01:55:39.769000             🧑  作者: Mango

红宝石 |数组 min()函数

Array#min() : min()是一个 Array 类方法,它返回此数组中的最小值。

示例 #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"

输出 :

min() method form : for

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

示例 #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"

输出 :

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

min() method form : ["I"]