Created
November 22, 2019 17:25
-
-
Save raulingg/9e18b8265f2b60d0a7906b7bf557741f to your computer and use it in GitHub Desktop.
resolve promise sequentially by reduce
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
[...cohortSlugs].reduce((prevPromise, slug) => { | |
let applications; | |
return prevPromise | |
.then((acc) => { | |
applications = acc; | |
return Cohort.findOne({ slug }); | |
}) | |
.then(({ _id: cohort }) => [ | |
...applications, | |
...applicationsFromFirestore | |
.filter(({ cohortId }) => cohortId === slug) | |
.map(({ cohortId, ...rest }) => ({ cohort, ...rest })), | |
]); | |
}, Promise.resolve([])); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment