source: node_modules/d3-array/src/leastIndex.js

Last change on this file was e4c61dd, checked in by istevanoska <ilinastevanoska@…>, 6 months ago

Prototype 1.1

  • Property mode set to 100644
File size: 467 bytes
Line 
1import ascending from "./ascending.js";
2import minIndex from "./minIndex.js";
3
4export default function leastIndex(values, compare = ascending) {
5 if (compare.length === 1) return minIndex(values, compare);
6 let minValue;
7 let min = -1;
8 let index = -1;
9 for (const value of values) {
10 ++index;
11 if (min < 0
12 ? compare(value, value) === 0
13 : compare(value, minValue) < 0) {
14 minValue = value;
15 min = index;
16 }
17 }
18 return min;
19}
Note: See TracBrowser for help on using the repository browser.