partitionSelect
partitionSelect(x, k)
partitionSelect(x, k, compare)
Partition-based selection of an array or 1D matrix. Will find the kth smallest value, and mutates the input array. Uses Quickselect.
Try it yourself:
$1 | partitionSelect([5, 10, 1], 2)
| |
$2 | partitionSelect(["C", "B", "A", "D"], 1, compareText)
| |
$3 | arr = [5, 2, 1]
| |
$4 | partitionSelect(arr, 0) # returns 1, arr is now: [1, 2, 5]
| |
$5 | arr
| |
$6 | partitionSelect(arr, 1, 'desc') # returns 2, arr is now: [5, 2, 1]
| |
$7 | arr
|
See also:
All functions