Partypack/Server/Source/Modules/Extensions.ts

4 lines
326 B
TypeScript
Raw Permalink Normal View History

2024-02-03 01:41:24 +01:00
// https://advancedweb.hu/how-to-use-async-functions-with-array-filter-in-javascript/
export async function AsyncFilter(arr: unknown[], predicate: (value: unknown, index: number, array: unknown[]) => Promise<boolean>) {
return Promise.all(arr.map(predicate)).then((results) => arr.filter((_v, index) => results[index]));
}