@extra-array/sort-on
v2.7.8
Published
Arranges values in an order.
Downloads
247
Readme
Arranges values in an order. :running: :vhs: :package: :moon:
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' ]