Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save WaldoJeffers/774142e2ea3e97fd3b126337b969d98f to your computer and use it in GitHub Desktop.
Save WaldoJeffers/774142e2ea3e97fd3b126337b969d98f to your computer and use it in GitHub Desktop.
const obj = { books: 10, ruler: 1, pencils: 5 }
const isEven = x => Promise.resolve(x % 2 === 0)
const result = await Promise
.all(Object.values(obj).map(isEven))
.then(results => Object.keys(obj).reduce((acc, key, index) => {
if (results[index]){
acc[key] = obj[key]
}
return acc
}, {}) // { books: 10 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment