Return Value 戻り値
A subsequence that leaves off the specified number of elements at the end.
Availability 有効性
Technology
func dropLast(_ k: Int
= 1) -> Self.SubSequence
A subsequence that leaves off the specified number of elements at the end.
k
The number of elements to drop off the end of the collection. k
must be greater than or equal to zero.
コレクションの終わりで省く要素の数。k
は、ゼロより大きいまたは等しくなければなりません。
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 Random
; otherwise, O(n), where n is the length of the collection.