UNPKG

330 BPlain TextView Raw
1import type {testFn} from './_types';
2
3/**
4 * Finds indices of values passing a test.
5 * @param x an array
6 * @param ft test function (v, i, x)
7 */
8function findIndices<T>(x: Iterable<T>, ft: testFn<T>): number[] {
9 var a = [], i = -1;
10 for(var v of x)
11 if(ft(v, ++i, x)) a.push(i);
12 return a;
13}
14export default findIndices;