Created
March 18, 2015 04:14
-
-
Save elwayman02/946677559a84d1f18192 to your computer and use it in GitHub Desktop.
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
function getWinPosition(joins, winner) { | |
var spots = joins.length; | |
var winningSpot; | |
var lockDistance = Math.floor(spots / 4); | |
if (lockDistance < 1) { lockDistance = 1;} | |
for (winningSpot = 0; winningSpot < lockDistance; winningSpot++) { | |
if (!joins[winningSpot]) { | |
break; | |
} | |
} | |
winningSpot++; // Convert array index to WL position | |
var lockRange = winner - (lockDistance - 1); | |
if (lockRange < winningSpot) { | |
winningSpot = lockRange; | |
} | |
return winningSpot; | |
} | |
Example: | |
Joins (true indicates that spot typed !join) - [true, true, true, false, false, true, true, false, true, false, true, true, true, false, true, true] | |
Winner - 6 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
202022859099