aboutsummaryrefslogtreecommitdiffstats
path: root/docs/solidity-by-example.rst
diff options
context:
space:
mode:
Diffstat (limited to 'docs/solidity-by-example.rst')
-rw-r--r--docs/solidity-by-example.rst16
1 files changed, 16 insertions, 0 deletions
diff --git a/docs/solidity-by-example.rst b/docs/solidity-by-example.rst
index 2e53b78c..dd208ea3 100644
--- a/docs/solidity-by-example.rst
+++ b/docs/solidity-by-example.rst
@@ -170,6 +170,22 @@ of votes.
}
}
}
+
+ function winnerName() constant
+ returns (bytes32 winnerName)
+ {
+ //Init a for loop that compares all the votes
+ //one at a time. If a higher count is found, the
+ //value is updated. p represents position of the
+ //proposed person's name in the array
+ uint winningVoteCount = 0;
+ for (uint p = 0; p < proposals.length; p++) {
+ if (proposals[p].voteCount > winningVoteCount) {
+ winningVoteCount = proposals[p].voteCount;
+ winnerName = proposals[p].name;
+ }
+ }
+ }
}
Possible Improvements