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.
This commit is contained in:
varunagarwal315 2016-11-03 13:02:25 +05:30 committed by GitHub
parent 1a2c150e3b
commit 4c105dba07

View File

@ -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