Created
October 12, 2020 07:46
-
-
Save natanavra/c9061a761f7be752c4a50107a7a8b508 to your computer and use it in GitHub Desktop.
Javascript Promise.all object with object implementation
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
module.exports = (obj) => { | |
const entries = Object.entries(obj); | |
return Promise | |
.all(entries.map(([, v]) => v)) | |
.then(results => results | |
.reduce((accumulator, value, idx) => { | |
const [key] = entries[idx]; | |
accumulator[key] = value; | |
return accumulator; | |
}, {})); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment