Created
May 26, 2018 16:20
-
-
Save WaldoJeffers/7cf4d99e70c9701cb64386b9c7e8e7bb to your computer and use it in GitHub Desktop.
Filter an array using an asynchronous predicate
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
const numbers = [3, 1, 4] | |
const isEven = x => Promise.resolve(x => x % 2 === 0) | |
const result = await Promise | |
.all(numbers.map(isEven))) | |
.then(results => numbers.filter((_, index) => results[index])) | |
// [4] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment