Skip to content

Instantly share code, notes, and snippets.

@og2t
Created February 25, 2011 14:46
Show Gist options
  • Save og2t/843879 to your computer and use it in GitHub Desktop.
Save og2t/843879 to your computer and use it in GitHub Desktop.
Winner's Ranking
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