UNPKG

@extra-array/range

Version:

Finds smallest and largest entries.

52 lines (37 loc) 1.32 kB
Finds smallest and largest entries. [:package:](https://www.npmjs.com/package/@extra-array/range) [:smiley_cat:](https://github.com/orgs/nodef/packages?repo_name=extra-array) [:running:](https://npm.runkit.com/@extra-array/range) [:vhs:](https://asciinema.org/a/332113) [:moon:](https://www.npmjs.com/package/@extra-array/range.min) [:scroll:](https://unpkg.com/@extra-array/range/) [:newspaper:](https://nodef.github.io/extra-array/) [:blue_book:](https://github.com/nodef/extra-array/wiki/) > Similar: [min], [max], [range]. > This is part of package [extra-array]. [extra-array]: https://www.npmjs.com/package/extra-array <br> ```javascript array.range(x, [fc], [fm]); // x: an array // fc: compare function (a, b) // fm: map function (v, i, x) // → [smallest, largest] ``` ```javascript const array = require("extra-array"); var x = [1, 2, -3, -4]; array.range(x); // [ [ 3, -4 ], [ 1, 2 ] ] array.range(x, (a, b) => Math.abs(a) - Math.abs(b)); // [ [ 0, 1 ], [ 3, -4 ] ] array.range(x, null, v => Math.abs(v)); // [ [ 0, 1 ], [ 3, -4 ] ] ``` <br> <br> ## References - [range: MATLAB](https://www.mathworks.com/help/stats/range.html) [min]: https://github.com/nodef/extra-array/wiki/min [max]: https://github.com/nodef/extra-array/wiki/max [range]: https://github.com/nodef/extra-array/wiki/range