Skip to content

Instantly share code, notes, and snippets.

@assertnotnull
Created September 3, 2015 16:12
Show Gist options
  • Save assertnotnull/a69bbe1314aeea177059 to your computer and use it in GitHub Desktop.
Save assertnotnull/a69bbe1314aeea177059 to your computer and use it in GitHub Desktop.
Simple sum of promises
var Q = require('q');
var myarr = [1,2,3,4,5];
Q.resolve(myarr).then(function (results) {
return results.reduce(function (prev, current) {
console.log(prev, current);
return prev + current;
})
}).then(function (sum) {
console.log(sum);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment