mirror of
https://github.com/nunocoracao/blowfish.git
synced 2025-02-02 11:32:30 -06:00
19 lines
467 B
JavaScript
19 lines
467 B
JavaScript
import ascending from "./ascending.js";
|
|
import minIndex from "./minIndex.js";
|
|
|
|
export default function leastIndex(values, compare = ascending) {
|
|
if (compare.length === 1) return minIndex(values, compare);
|
|
let minValue;
|
|
let min = -1;
|
|
let index = -1;
|
|
for (const value of values) {
|
|
++index;
|
|
if (min < 0
|
|
? compare(value, value) === 0
|
|
: compare(value, minValue) < 0) {
|
|
minValue = value;
|
|
min = index;
|
|
}
|
|
}
|
|
return min;
|
|
}
|