The maximum number of elements to return.
返される要素の最大限の数。
The value of max
must be greater than or equal to zero.
Instance Method
インスタンスメソッド
suffix(_:)
Returns a subsequence, up to the given maximum length, containing the final elements of the sequence.
Availability 有効性
- iOS 13.0+
- iPadOS 13.0+
- macOS 10.15+
- Mac Catalyst 13.0+
- tvOS 13.0+
- watchOS 6.0+
Technology
- Swift
UI
Declaration 宣言
func suffix(_ maxLength: Int
) -> [Self.Element]
Parameters パラメータ
maxLength
Length
Discussion 議論
The sequence must be finite. If the maximum length exceeds the number of elements in the sequence, the result contains all the elements in the sequence.
let numbers = [1, 2, 3, 4, 5]
print(numbers.suffix(2))
// Prints "[4, 5]"
print(numbers.suffix(10))
// Prints "[1, 2, 3, 4, 5]"
Complexity
O(n), where n is the length of the sequence.