UNPKG

@extra-array/max-index

Version:
42 lines (32 loc) 1.29 kB
Finds index of largest value. [:running:] [:vhs:] [:package:] [:moon:] [:ledger:] > Alternatives: [max], [maxIndex].<br> > Similar: [min], [max], [range].<br> > This is part of package [extra-array]. [extra-array]: https://www.npmjs.com/package/extra-array ```javascript array.maxIndex(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 = [1, 2, -3, -4]; array.maxIndex(x); // 1 ^ array.maxIndex(x, (a, b) => Math.abs(a) - Math.abs(b)); // 3 ^ array.maxIndex(x, null, v => Math.abs(v)); // 3 ^ ``` ### references - [Math.max: MDN web docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/max) [max]: https://github.com/nodef/extra-array/wiki/max [maxIndex]: https://github.com/nodef/extra-array/wiki/maxIndex [min]: https://github.com/nodef/extra-array/wiki/min [range]: https://github.com/nodef/extra-array/wiki/range [:running:]: https://npm.runkit.com/@extra-array/max-index [:package:]: https://www.npmjs.com/package/@extra-array/max-index [:moon:]: https://www.npmjs.com/package/@extra-array/max-index.min [:ledger:]: https://unpkg.com/@extra-array/max-index/ [:vhs:]: https://asciinema.org/a/332096