红宝石 |数组 max()函数
Array#max() : max()是一个 Array 类方法,它返回这个数组中的最大值。
Syntax: Array.max()
Parameter: Array
Return: the maximum value in this array.
示例 #1:
# Ruby code for max() method
# declaring array
a = %w[for geeks]
# max method example
puts "max() method form : #{a.max()}\n\n"
puts "max() method form : #{a.max(2)}\n\n"
输出 :
max() method form : geeks
max() method form : ["geeks", "for"]
示例 #2:
# Ruby code for max() method
# declaring array
a = %w[hi I can code for geeks]
# max method example
puts "max() method form : #{a.max(4)}\n\n"
puts "max() method form : #{a.max(1)}\n\n"
输出 :
max() method form : ["hi", "geeks", "for", "code"]
max() method form : ["hi"]