Created
February 25, 2011 14:46
-
-
Save og2t/843879 to your computer and use it in GitHub Desktop.
Winner's Ranking
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var scores:Array = [5, 20, 20, 10]; | |
var ranks:Array = scores.sort(Array.NUMERIC | Array.DESCENDING | Array.RETURNINDEXEDARRAY); | |
var winners:Array = []; | |
var highScores:Array = scores.sort(Array.NUMERIC | Array.DESCENDING); | |
var lastIndex:int = highScores.lastIndexOf(highScores[0]); | |
while (lastIndex-- >= 0) winners.push(ranks.shift() + 1); | |
winners.sort(Array.NUMERIC); | |
if (winners.length == 1) trace("PLAYER " + winners[0] + " WINS!"); | |
else if (winners.length == 2) trace("PLAYERS " + winners[0] + " & " + winners[1] + " WIN!"); | |
else if (winners.length == 3) trace("PLAYERS " + winners[0] + ", " + winners[1] + " & " + winners[2] + " WIN!"); | |
else trace("ALL PLAYERS DRAW!"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment