-
-
Save jgcmarins/78c2d43163832af44e039cd94aaceb9e to your computer and use it in GitHub Desktop.
Simple filter async
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function mapAsync<T, U>(array: T[], callbackfn: (value: T, index: number, array: T[]) => Promise<U>): Promise<U[]> { | |
return Promise.all(array.map(callbackfn)); | |
} | |
async function filterAsync<T>(array: T[], callbackfn: (value: T, index: number, array: T[]) => Promise<boolean>): Promise<T[]> { | |
const filterMap = await mapAsync(array, callbackfn); | |
return array.filter((value, index) => filterMap[index]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment