Skip to content

Instantly share code, notes, and snippets.

@joepie91
Last active June 25, 2023 09:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joepie91/ac1ee270c6a506405d5f to your computer and use it in GitHub Desktop.
Save joepie91/ac1ee270c6a506405d5f to your computer and use it in GitHub Desktop.
Flatten array with promises
module.exports = function(array) {
return array.reduce(function(total, subArray) {
subArray.forEach(function(item) {
total.push(item);
});
return total;
}, []);
}
var flatten = require("./flatten");
doThing().map(function(item){
...
}).then(flatten).then(function(flattenedArray) {
...
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment