Created
December 19, 2014 08:55
-
-
Save michalgorny/d6de0650f9cd623223b1 to your computer and use it in GitHub Desktop.
Parse Cloud Code - calculation average
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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