Swift:max方法

一、func max(_: T, _: T)

Returns the greater of two comparable values.
返回比较的两个值中最大的一个

Parameters: 参数
x: A value to compare.
y: Another value to compare.
Returns: The greater of x and y.
If x is equal to y, returns y.

返回:x 和 y 比较最大值。如果x 等于 y , 返回 y.

Declaration:声明
func max(_ x: T, _ y: T) -> T where T : Comparable


二、func max(_: T, _: T, _: T, _: T…)

Returns the greatest argument passed.
返回最大的参数

Parameters:
x: A value to compare.
y: Another value to compare.
z: A third value to compare.
rest: Zero or more additional values.

Returns:
The greatest of all the arguments. If there are multiple equal greatest arguments, the result is the last one.
所有参数的最大。 如果多个数等于最大的参数,返回最后一个。

Declaration
func max(_ x: T, _ y: T, _ z: T, _ rest: T…) -> T where T : Comparable


三、func max()
Returns the maximum element in the sequence.

This example finds the largest value in an array of height measurements.

let heights = [67.5, 65.7, 64.3, 61.1, 58.5, 60.3, 64.9]
let greatestHeight = heights.max()
print(greatestHeight)
// Prints "Optional(67.5)"

Returns: The sequence’s maximum element. If the sequence has no elements, returns nil.

Declaration
@warn_unqualified_access
func max() -> Self.Element?
Declared In
Sequence

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值