@extra-array/find-indices
Version:
Finds indices of values passing a test.
15 lines (13 loc) • 330 B
text/typescript
import type {testFn} from './_types';
/**
* Finds indices of values passing a test.
* @param x an array
* @param ft test function (v, i, x)
*/
function findIndices<T>(x: Iterable<T>, ft: testFn<T>): number[] {
var a = [], i = -1;
for(var v of x)
if(ft(v, ++i, x)) a.push(i);
return a;
}
export default findIndices;