FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

rangedSort · nodef/extra-array Wiki · GitHub

rangedSort

Subhajit Sahu edited this page May 3, 2023 · 1 revision

Arrange a range of values in order.

Alternatives: rangedSort, rangedSort$.
Similar: sort, rangedSort, partialSort, rangedPartialSort.


function rangedSort(x, i, I, fc, fm, fs)
// x:  an array
// i:  begin index
// I:  end index (exclusive)
// fc: compare function (a, b)
// fm: map function (v, i, x)
// fs: swap function (x, i, j)
const xarray = require('extra-array');


// Sort a range of values (index 0 to 2).
var x = [4, -3, 1, -2];
xarray.rangedSort(x, 0, 2);
// → [ -3, 4, 1, -2 ]  (compares numbers)


// Sort a range of values (index 0 to 3).
xarray.rangedSort(x, 0, 2);
// → [ -3, 1, 4, -2 ]


// Sort using absolute values.
xarray.rangedSort(x, 0, 3, null, v => Math.abs(v));
// → [ 1, -3, 4, -2 ]


References

Wiki pages Pages 196

Clone this wiki locally


Back | FazBrowse Home | New Git URL