fix: dont use empty strings as names

This commit is contained in:
eneller
2024-10-04 12:00:21 +02:00
parent 807a142b6d
commit ecbee0765c

View File

@@ -10,7 +10,11 @@ function randomizeTeams() {
} }
const outputField = document.getElementById("teamOutput"); const outputField = document.getElementById("teamOutput");
let textinput = document.getElementById("playerNames").value; let textinput = document.getElementById("playerNames").value;
let names = textinput.split('\n').map(function(str){return str.trim();}); let names = textinput
.split('\n')
.map(function(str){return str.trim();})
.filter(function(str){return str}); // boolean interpretation is same as non-empty
teams = Array.from({ length: teamCount }, () => []); teams = Array.from({ length: teamCount }, () => []);
playersPerTeam = Math.floor(names.length / teamCount); playersPerTeam = Math.floor(names.length / teamCount);