Instance Method インスタンスメソッド

suffix(_:)

Returns a subsequence, up to the given maximum length, containing the final elements of the collection. 下位シーケンスを、指定された最大長まで、コレクションの末尾の要素を含めて返します。

Declaration 宣言

func suffix(_ maxLength: Int) -> Slice<ReversedCollection<Base>>

Parameters パラメータ

maxLength

The maximum number of elements to return. maxLength must be greater than or equal to zero. 返される要素の最大限の数。maxLengthは、ゼロより大きいか等しくなければなりません。

Return Value 戻り値

A subsequence terminating at the end of the collection with at most maxLength elements. コレクションの末端で終わっていて多くともmaxLengthの要素を持つ下位シーケンス。

Discussion 解説

If the maximum length exceeds the number of elements in the collection, the result contains the entire collection. 最大長がコレクションの要素の数を越えるならば、結果はコレクション全体を含みます。


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(1) if the collection conforms to RandomAccessCollection; otherwise, O(k), where k is equal to maxLength. 計算量:コレクションがRandomAccessCollectionに準拠するならば、O(1);そうでなければ、O(k)、そこでkmaxLengthに相当します。