-
Notifications
You must be signed in to change notification settings - Fork 5
sort$
Subhajit Sahu edited this page May 19, 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 = [-2, -3, 1, 4];
array.sort$(x);
// [ -3, -2, 1, 4 ] (compares numbers)
x;
// [ -3, -2, 1, 4 ]
var x = [-2, -3, 1, 4];
array.sort$(x, (a, b) => Math.abs(a) - Math.abs(b));
// [ 1, -2, -3, 4 ]
var x = [-2, -3, 1, 4];
array.sort$(x, null, v => Math.abs(v));
// [ 1, -2, -3, 4 ]