Array filter with
Async
callback function.
Syntax
aFilter(
arr: T[],
cb: (value: T, index: number) => Promise<boolean>
): Promise<Partial<T[]>>
Usage
import { aFilter } from "@opentf/std";
aFilter([], async (value, index) => {});
Examples
const arr = [1, 2, 3, 4, 5];
function isEven(n) {
return new Promise((resolve) => {
resolve(n % 2 === 0);
});
}
const filteredArr = await aFilter(arr, async (n) => await isEven(n));
console.log(filteredArr); //=> [2, 4]