min(count:)

Returns the smallest elements of this collection.

MinMax.swift:354
func min(count: Int) -> [Element]

Parameters

count

The number of elements to return. If count is greater than the number of elements in this collection, all of the collection’s elements are returned.

Returns

An array of the smallest count elements of this collection.

This example partially sorts an array of integers to retrieve its three smallest values:

let numbers = [7, 1, 6, 2, 8, 3, 9]
let smallestThree = numbers.min(count: 3)
// [1, 2, 3]

If you need to sort a collection but only need to access its smallest elements, using this method can give you a performance boost over sorting the entire collection. The order of equal elements is guaranteed to be preserved.