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

dropLast(_:)

Returns a subsequence containing all but the specified number of final elements. 指定された数の末尾要素以外すべてを含んでいる下位シーケンスを返します。

Declaration 宣言

func dropLast(_ k: Int) -> Data

Parameters パラメータ

k

The number of elements to drop off the end of the collection. k must be greater than or equal to zero. コレクションの終わりで省く要素の数。kは、ゼロより大きいまたは等しくなければなりません。

Return Value 戻り値

A subsequence that leaves off k elements from the end. ある下位シーケンス、それはk個の要素を終わりから取り除いたものです。

Discussion 議論

If the number of elements to drop exceeds the number of elements in the collection, the result is an empty subsequence. 省かれることになる要素の数がコレクションの要素の数を超えるならば、結果は空の下位シーケンスになります。


let numbers = [1, 2, 3, 4, 5]
print(numbers.dropLast(2))
// Prints "[1, 2, 3]"
print(numbers.dropLast(10))
// Prints "[]"

Complexity: O(1) if the collection conforms to RandomAccessCollection; otherwise, O(k), where k is the number of elements to drop. 計算量:O(1)、もしコレクションがRandomAccessCollectionに準拠するならば;そうでなければ、O(k)、ここでkは除外する要素の数です。

See Also 参照

Excluding Bytes バイトを排除する