Find kth smallest element in an arary of numbers
Uses a randomized quickselect to achieve O(n) average case time complexity
$ npm install kth-smallestimport kthSmallest from 'kth-smallest'
kthSmallest([10, 20, 30, 40], 0)
// 10
kthSmallest([10, 20, 30, 40], 2)
// 30
kthSmallest([10, 20, 30, 40], -1)
// 40kthSmallest :: number a => [a] -> integer -> a
kthSmallest(numbers, k)Arguments
numbers- An array of numbersk- 0-indexed target (pass negative numbers for largest)