Arranges values in an order.
Alternatives: compare, compare-update, map, map-update.
This is part of package extra-array.
array.sortOn(x, [fn], [ths]);
// x: an array
// fn: map function (v, i, x)
// ths: this argument
const array = require('extra-array');
var x = [-3, -2, 1, 4];
array.sortOn(x, v => Math.abs(v));
// [ 1, -2, -3, 4 ]
var x = ['B', 'D', 'a', 'c'];
array.sortOn(x, v => v.toLowerCase());
// [ 'a', 'B', 'c', 'D' ]