function _partitionSelect (x, k, compare) {
    if (!isInteger(k) || k < 0) {
      throw new Error('k must be a non-negative integer')
    }

    if (isMatrix(x)) {
      const size = x.size()
      if (size.length > 1) {
        throw new Error('Only one dimensional matrices supported')
      }
      return quickSelect(x.valueOf(), k, compare)
    }

    if (Array.isArray(x)) {
      return quickSelect(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.

Syntax:

   math.partitionSelect(x, k)
   math.partitionSelect(x, k, compare)

Examples:

   math.partitionSelect([5, 10, 1], 2)                               // returns 10
   math.partitionSelect(['C', 'B', 'A', 'D'], 1, math.compareText)   // returns 'B'

   function sortByLength (a, b) {
     return a.length - b.length
   }
   math.partitionSelect(['Langdon', 'Tom', 'Sara'], 2, sortByLength) // returns 'Langdon'

   // the input array is mutated
   arr = [5, 2, 1]
   math.partitionSelect(arr, 0) // returns 1, arr is now: [1, 2, 5]
   math.partitionSelect(arr, 1, 'desc') // returns 2, arr is now: [5, 2, 1]

See also:

   sort

@param {Matrix | Array} x    A one dimensional matrix or array to sort
@param {Number} k            The kth smallest value to be retrieved zero-based index
@param {Function | 'asc' | 'desc'} [compare='asc']
       An optional comparator function. The function is called as
       `compare(a, b)`, and must return 1 when a > b, -1 when a < b,
       and 0 when a == b.
@return {*} Returns the kth lowest value.