mirror of
https://github.com/zoriya/flood.git
synced 2026-08-15 18:53:27 +00:00
15 lines
313 B
TypeScript
15 lines
313 B
TypeScript
export async function asyncFilter<T>(
|
|
array: Array<T>,
|
|
predicate: (item: T, index: number) => Promise<boolean>,
|
|
): Promise<Array<T>> {
|
|
const results: T[] = [];
|
|
|
|
for (const [index, item] of array.entries()) {
|
|
if (await predicate(item, index)) {
|
|
results.push(item);
|
|
}
|
|
}
|
|
|
|
return results;
|
|
}
|