dropLast(_:)

Tabber·2021년 7월 13일
0

Apple Document

목록 보기
9/12

Instance Method

Returns a subsequence containing all but the specified number of final elements.
지정된 수의 최종 요소를 제외한 모든 요소를 포함하는 시퀀스를 반환합니다.

Parameters

k

  • The number of elements to drop off the end of the collection. k must be greater than or equal to zero.
    컬렉션 끝에서 떨어뜨릴 요소 수입니다. k는 0보다 크거나 같아야 합니다.

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)이고, 그렇지 않은 경우 O(k), 여기서 k는 삭제할 요소의 수입니다.

profile
iOS 정복중인 Tabber 입니다.

0개의 댓글