Skip to content

Instantly share code, notes, and snippets.

@tkssharma
Created September 30, 2017 07:43
Show Gist options
  • Save tkssharma/c048b48c15e71a86e4f36ed57a83b2c7 to your computer and use it in GitHub Desktop.
Save tkssharma/c048b48c15e71a86e4f36ed57a83b2c7 to your computer and use it in GitHub Desktop.
function findLikesForPostsByUsername(username, callback) {
findUserByUsername(username, function(err, user) {
if(err) return callback(err)
findPostsByUser(user, function(err, posts) {
if(err) return callback(err)
findLikesByPosts(posts, function(err, likes) {
if(err) return callback(err)
var totalLikes = likes.reduce(function(x, y) {
return x + y
})
callback(null, totalLikes)
})
})
})
}
var username = 'seanghagstrom'
findLikesForPostsByUsername(username, function(err, totalLikes) {
if(err) {
console.error(err)
} else {
console.log(username + ' total number of likes: ' + totalLikes)
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment