红宝石 |数组 min()函数
Array#min() : min()是一个 Array 类方法,它返回此数组中的最小值。
Syntax: Array.min()
Parameter: Array
Return: the minimum value in this 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"]