Finding the Minimum and Maximum
Find the minimum and maximum elements simultaneously, or a specific number of elements at the minimum and maximum.
Finding Minimum or Maximum Elements
func min(count: Int
) -> [Element] Returns the smallest elements of this sequence.
func min(count: Int
) -> [Element] Returns the smallest elements of this collection.
func min(count: Int, sortedBy: (Element, Element) throws -> Bool
) rethrows -> [Element] Returns the smallest elements of this sequence, as sorted by the given predicate.
func min(count: Int, sortedBy: (Element, Element) throws -> Bool
) rethrows -> [Element] Returns the smallest elements of this collection, as sorted by the given predicate.
func max(count: Int
) -> [Element] Returns the largest elements of this sequence.
func max(count: Int
) -> [Element] Returns the largest elements of this collection.
func max(count: Int, sortedBy: (Element, Element) throws -> Bool
) rethrows -> [Element] Returns the largest elements of this sequence, as sorted by the given predicate.
func max(count: Int, sortedBy: (Element, Element) throws -> Bool
) rethrows -> [Element] Returns the largest elements of this collection, as sorted by the given predicate.
Finding the Minimum and Maximum Elements Simulataneously
func minAndMax(
) -> (min: Element, max: Element)? Returns both the minimum and maximum elements in the sequence.
func minAndMax(by: (Element, Element) throws -> Bool
) rethrows -> (min: Element, max: Element)? Returns both the minimum and maximum elements in the sequence, using the given predicate as the comparison between elements.