Skip to content

Instantly share code, notes, and snippets.

@natanavra
Created October 12, 2020 07:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save natanavra/c9061a761f7be752c4a50107a7a8b508 to your computer and use it in GitHub Desktop.
Save natanavra/c9061a761f7be752c4a50107a7a8b508 to your computer and use it in GitHub Desktop.
Javascript Promise.all object with object implementation
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