To find the kth largest number in a list in Swift, one approach is to sort the array in descending order and return the element at index k-1. Here's an implementation of this approach:
main.swift270 chars8 lines
You can use this function as follows:
main.swift259 chars7 lines
Note that the function returns an optional, as the input might be invalid (if k is out of range).
gistlibby LogSnag