Skip to content

Instantly share code, notes, and snippets.

@michalgorny
Created December 19, 2014 08:55
Show Gist options
  • Save michalgorny/d6de0650f9cd623223b1 to your computer and use it in GitHub Desktop.
Save michalgorny/d6de0650f9cd623223b1 to your computer and use it in GitHub Desktop.
Parse Cloud Code - calculation average
Parse.Cloud.define("averageFeelings", function(request, response) {
var query = new Parse.Query("ratings");
query.find({
success: function(results) {
var sum = 0;
for (var i = 0; i < results.length; ++i) {
sum += results[i].get("feelings");
}
response.success(sum / results.length);
},
error: function() {
response.error("Calculating ratings failed");
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment