Last active
January 22, 2019 08:37
-
-
Save abdullah/f64e8bcb734b3886f7b1c8ce04d2d0d8 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
/* | |
BODEV Office | |
1 July 2016 | |
@author : Abdullah mara | |
Bu script 1 Temmuz 2016'da bodevoffice developer'larının langırt turnuvasındaki takımları | |
belirlemek için yazılmıştır | |
*/ | |
// Participant names. | |
var players = [ | |
"Abdullah", | |
"Bircan", | |
"Özge", | |
"Süleyman", | |
"Burak", | |
"George", | |
"Can", | |
"Yusuf", | |
"Lütfi", | |
"Nukhet" | |
]; | |
// Teams | |
var teams = []; | |
// They will not be on the same team. | |
// Because they very good player. | |
var notSameTeam = ["Abdullah","Said","George"]; | |
// Random players | |
function tombala() { | |
var index = Math.floor(Math.random() * players.length); | |
return {index:index , players : players[index]}; | |
} | |
var state = true; | |
while(state){ | |
if (players.length) { | |
var player_first = tombala(); | |
var player_second = tombala(); | |
var firstexp = notSameTeam.indexOf(player_first.players) | |
var secondexp = notSameTeam.indexOf(player_second.players) | |
var exp = firstexp != -1 && secondexp != -1; | |
if (player_first.index == player_second.index || exp) { | |
state = true | |
}else{ | |
players = filterPlayers(player_first.players); | |
players = filterPlayers(player_second.players); | |
teams.push({ | |
first:player_first, | |
second:player_second | |
}); | |
} | |
}else{ | |
state = false; | |
Object.keys(teams).map(function(index, elem) { | |
console.log(teams[elem].first.players ," + " , teams[elem].second.players) | |
}) | |
} | |
} | |
function filterPlayers(ob) { | |
return players.filter(function(index) { | |
return index != ob; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment