Removes unused minIndex/maxIndex.

This commit is contained in:
Henning Dieterichs 2021-12-08 12:43:06 +01:00
parent e3544ad159
commit 0d50a57bc5
No known key found for this signature in database
GPG key ID: 771381EFFDB9EC06
2 changed files with 0 additions and 50 deletions

View file

@ -591,40 +591,6 @@ function getActualStartIndex<T>(array: T[], start: number): number {
return start < 0 ? Math.max(start + array.length, 0) : Math.min(start, array.length);
}
/**
* Like Math.min with a delegate, and returns the winning index
*/
export function minIndex<T>(array: readonly T[], fn: (value: T) => number): number {
let minValue = Number.MAX_SAFE_INTEGER;
let minIdx = 0;
array.forEach((value, i) => {
const thisValue = fn(value);
if (thisValue < minValue) {
minValue = thisValue;
minIdx = i;
}
});
return minIdx;
}
/**
* Like Math.max with a delegate, and returns the winning index
*/
export function maxIndex<T>(array: readonly T[], fn: (value: T) => number): number {
let minValue = Number.MIN_SAFE_INTEGER;
let maxIdx = 0;
array.forEach((value, i) => {
const thisValue = fn(value);
if (thisValue > minValue) {
minValue = thisValue;
maxIdx = i;
}
});
return maxIdx;
}
/**
* A comparator `c` defines a total order `<=` on `T` as following:
* `c(a, b) <= 0` iff `a` <= `b`.

View file

@ -338,22 +338,6 @@ suite('Arrays', () => {
assert.strictEqual(array[6], 7);
});
test('minIndex', () => {
const array = ['a', 'b', 'c'];
assert.strictEqual(arrays.minIndex(array, value => array.indexOf(value)), 0);
assert.strictEqual(arrays.minIndex(array, value => -array.indexOf(value)), 2);
assert.strictEqual(arrays.minIndex(array, _value => 0), 0);
assert.strictEqual(arrays.minIndex(array, value => value === 'b' ? 0 : 5), 1);
});
test('maxIndex', () => {
const array = ['a', 'b', 'c'];
assert.strictEqual(arrays.maxIndex(array, value => array.indexOf(value)), 2);
assert.strictEqual(arrays.maxIndex(array, value => -array.indexOf(value)), 0);
assert.strictEqual(arrays.maxIndex(array, _value => 0), 0);
assert.strictEqual(arrays.maxIndex(array, value => value === 'b' ? 5 : 0), 1);
});
test('findMaxBy', () => {
const array = [{ v: 3 }, { v: 5 }, { v: 2 }, { v: 2 }, { v: 2 }, { v: 5 }];