Skip to content

Instantly share code, notes, and snippets.

@WaldoJeffers
Created May 26, 2018 16:20
Show Gist options
  • Save WaldoJeffers/7cf4d99e70c9701cb64386b9c7e8e7bb to your computer and use it in GitHub Desktop.
Save WaldoJeffers/7cf4d99e70c9701cb64386b9c7e8e7bb to your computer and use it in GitHub Desktop.
Filter an array using an asynchronous predicate
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