File tree Expand file tree Collapse file tree 4 files changed +280
-244
lines changed
Expand file tree Collapse file tree 4 files changed +280
-244
lines changed Original file line number Diff line number Diff line change @@ -317,14 +317,22 @@ contract Competition {
317317 * @param _proposalId proposal id
318318 * @param _suggestionId suggestion id
319319 */
320+ // solhint-disable-next-line code-complexity
320321 function refreshTopSuggestions (bytes32 _proposalId , uint256 _suggestionId ) private {
321322 uint256 [] storage topSuggestions = proposals[_proposalId].topSuggestions;
322- if (topSuggestions.length < proposals[_proposalId].numberOfWinners) {
323+ uint256 topSuggestionsLength = topSuggestions.length ;
324+ uint256 i;
325+ if (topSuggestionsLength < proposals[_proposalId].numberOfWinners) {
326+ for (i = 0 ; i < topSuggestionsLength; i++ ) {
327+ if (topSuggestions[i] == _suggestionId) {
328+ return ;
329+ }
330+ }
323331 topSuggestions.push (_suggestionId);
324332 } else {
325333 /** get the index of the smallest element **/
326334 uint256 smallest = 0 ;
327- for (uint256 i ; i < proposals[_proposalId].numberOfWinners; i++ ) {
335+ for (i = 0 ; i < proposals[_proposalId].numberOfWinners; i++ ) {
328336 if (suggestions[topSuggestions[i]].totalVotes <
329337 suggestions[topSuggestions[smallest]].totalVotes) {
330338 smallest = i;
You can’t perform that action at this time.
0 commit comments