Created
July 29, 2020 12:31
-
-
Save sibelius/e39d94c2bee2adb11f0f7239898e072d to your computer and use it in GitHub Desktop.
Simple filter async
This file contains hidden or 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