Skip to content

Instantly share code, notes, and snippets.

@elwayman02
Created March 18, 2015 04:14
Show Gist options
  • Save elwayman02/946677559a84d1f18192 to your computer and use it in GitHub Desktop.
Save elwayman02/946677559a84d1f18192 to your computer and use it in GitHub Desktop.
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
@abinashpakhrin
Copy link

202022859099

@Renchi00
Copy link

202033238593

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment