Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: Glench/Snaplab-Ultimatum
base: 4b6e96e80f
...
head fork: Glench/Snaplab-Ultimatum
compare: 34738cdb01
  • 2 commits
  • 1 file changed
  • 0 commit comments
  • 1 contributor
Showing with 12 additions and 25 deletions.
  1. +12 −25 ultimatum.js
View
37 ultimatum.js
@@ -243,15 +243,13 @@ var Ultimatum = function(numPlayers, totalAmount, percentNeeded, currentPlayerId
ultimatum.enoughAccepted = function() {
// returns true if the percent accepting is above the percent needed
// for a success
- var totalAccepted = 0,
- percentAccepted,
- player;
- for (var i = 0; i < this.players.length; ++i) {
- player = this.players[i];
+ var totalAccepted = _.reduce(this.players, function(player) {
if (player.acceptedOffer) {
- totalAccepted += 1;
+ return 1;
+ } else {
+ return 0;
}
- }
+ }, 0);
return (totalAccepted / this.players.length) > this.percentNeeded;
}
@@ -259,33 +257,22 @@ var Ultimatum = function(numPlayers, totalAmount, percentNeeded, currentPlayerId
ultimatum.validate = function() {
// have to validate they didn't put an amount over the total that they
// were allowed to put
- if (ultimatum.calculatedTotal() != ultimatum.totalAmount) {
- return false;
- }
- return true;
+ return ultimatum.calculatedTotal() == ultimatum.totalAmount;
};
ultimatum.validatePlayers = function() {
// have to validate they didn't put an amount over the total that they
// were allowed to put
- var player;
- for (var i=0; i < this.players.length; ++i) {
- player = this.players[i];
- if (!player.validate()) {
- return false;
- }
- }
- return true;
+ return _.all(this.players, function(player) {
+ return player.validate();
+ });
};
ultimatum.allOffersProcessed = function() {
// return false if any player has a null acceptedOffer attribute
- for (var i = 0; i < this.players.length; ++i) {
- if (_.isNull(this.players[i].acceptedOffer)) {
- return false;
- }
- }
- return true;
+ return _.all(this.players, function(player) {
+ return !_.isNull(player.acceptedOffer)
+ });
};
ultimatum.renderTemplate = function(selector, params) {

No commit comments for this range

Something went wrong with that request. Please try again.