-
Notifications
You must be signed in to change notification settings - Fork 5
sort$
wolfram77 edited this page Mar 25, 2020
·
19 revisions
Arranges values in an order.
Alternatives: [compare], [compare-update], [map], [map-update].
array.sort$(x, [fn]);
// x: an array (updated)
// fn: compare function (a, b)
// --> x
const array = require('extra-array');
var x = [-3, -2, 1, 4];
array.sort$(x, (a, b) => Math.abs(a) - Math.abs(b));
// [ 1, -2, -3, 4 ]
x;
// [ 1, -2, -3, 4 ]
var x = ['B', 'D', 'a', 'c'];
array.sort$(x, (a, b) => a.toLowerCase().localeCompare(b.toLowerCase()));
// [ 'a', 'B', 'c', 'D' ]