-
-
Save nomanalikhan/0be1a9c53c61d765d90fb6ca3090fec4 to your computer and use it in GitHub Desktop.
return a flatten map resolved by async function
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
async function asyncFlatMap (arr, asyncFn) { | |
return Promise.all(flatten(await asyncMap(arr, asyncFn))) | |
} | |
function asyncMap (arr, asyncFn) { | |
return Promise.all(arr.map(asyncFn)) | |
} | |
function flatMap (arr, fn) { | |
return flatten(arr.map(fn)) | |
} | |
function flatten (arr) { | |
return [].concat(...arr) | |
} | |
module.exports = { | |
asyncFlatMap, | |
asyncMap, | |
flatMap, | |
flatten | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment