Instance Method

dropLast()

Returns a subsequence containing all but the last element of the sequence.

Declaration

func dropLast() -> AnySequence<Element>

Return Value

A subsequence leaving off the last element of the sequence.

Discussion

The sequence must be finite.

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

If the sequence has no elements, the result is an empty subsequence.

let empty: [Int] = []
print(empty.dropLast())
// Prints "[]"

Complexity: O(n), where n is the length of the sequence.