-
Notifications
You must be signed in to change notification settings - Fork 5
partialSort
Subhajit Sahu edited this page May 3, 2023
·
1 revision
Partially arrange values in order.
Alternatives: partialSort, partialSort$.
Similar: sort, rangedSort, partialSort, rangedPartialSort.
function partialSort(x, n, fc, fm, fs)
// x: an array
// n: minimum number of values to sort
// fc: compare function (a, b)
// fm: map function (v, i, x)
// fs: swap function (x, i, j)
const xarray = require('extra-array');
// Partially sort, such that first 2 values are guaranteed to be sorted.
var x = [4, -3, 1, -2];
xarray.partialSort(x, 2);
// → [ -3, 1, 4, -2 ]
// Partially sort using absolute values.
xarray.partialSort(x, 2, null, v => Math.abs(v));
// → [ 1, -3, 4, -2 ]