aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvarunagarwal315 <varunagarwal315@gmail.com>2016-11-03 15:32:25 +0800
committerGitHub <noreply@github.com>2016-11-03 15:32:25 +0800
commit4c105dba0714564c2a31dac5ded8e994d0625dd1 (patch)
treed5e32164b30e181aad1d44735dea7585c96dbaa4
parent1a2c150e3b2f98ef44834aca281692734b74c0db (diff)
downloaddexon-solidity-4c105dba0714564c2a31dac5ded8e994d0625dd1.tar.gz
dexon-solidity-4c105dba0714564c2a31dac5ded8e994d0625dd1.tar.zst
dexon-solidity-4c105dba0714564c2a31dac5ded8e994d0625dd1.zip
Update solidity-by-example.rst
Might be trivial, but makes more sense to be able to directly return the name of the winner for the election. If the position of the winner on the proposal[] array is returned, then people still don't know the name of the person who won.
-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