@extra-array/sort
Version:
Arranges values in an order.
55 lines (40 loc) • 1.64 kB
Markdown
Arranges values in an order.
[:package:](https://www.npmjs.com/package/@extra-array/sort)
[:smiley_cat:](https://github.com/orgs/nodef/packages?repo_name=extra-array)
[:running:](https://npm.runkit.com/@extra-array/sort)
[:vhs:](https://asciinema.org/a/332134)
[:moon:](https://www.npmjs.com/package/@extra-array/sort.min)
[:scroll:](https://unpkg.com/@extra-array/sort/)
[: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
// fc: compare function (a, b)
// fm: map function (v, i, x)
```
```javascript
const array = require("extra-array");
var x = [-2, -3, 1, 4];
array.sort(x);
// [ -3, -2, 1, 4 ] (compares numbers)
array.sort(x, (a, b) => Math.abs(a) - Math.abs(b));
// [ 1, -2, -3, 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)
- [immutable-array-prototype: @azu](https://github.com/azu/immutable-array-prototype)
- [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