UNPKG

@extra-array/sort-update

Version:
60 lines (44 loc) 1.68 kB
Arranges values in an order. [:package:](https://www.npmjs.com/package/@extra-array/sort-update) [:smiley_cat:](https://github.com/orgs/nodef/packages?repo_name=extra-array) [:running:](https://npm.runkit.com/@extra-array/sort-update) [:vhs:](https://asciinema.org/a/332133) [:moon:](https://www.npmjs.com/package/@extra-array/sort-update.min) [:scroll:](https://unpkg.com/@extra-array/sort-update/) [:newspaper:](https://nodef.github.io/extra-array/) [:blue_book:](https://github.com/nodef/extra-array/wiki/) > Alternatives: [sort], [sort$].<br> > Similar: [sort], [merge]. > This is part of package [extra-array]. [extra-array]: https://www.npmjs.com/package/extra-array <br> ```javascript array.sort$(x, [fc], [fm]); // x: an array (updated) // fc: compare function (a, b) // fm: map function (v, i, x) // → x ``` ```javascript 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 ] ``` <br> <br> ## References - [Data.Sort.sortBy: Haskell](https://hackage.haskell.org/package/sort-1.0.0.0/docs/Data-Sort.html#v:sortBy) - [Array.prototype.sort: MDN web docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort) - [Array.sortBy: sugarjs](https://sugarjs.com/docs/#/Array/sortBy) [sort]: https://github.com/nodef/extra-array/wiki/sort [sort$]: https://github.com/nodef/extra-array/wiki/sort$ [merge]: https://github.com/nodef/extra-array/wiki/merge