diff options
Diffstat (limited to 'utils.mjs')
| -rw-r--r-- | utils.mjs | 31 |
1 files changed, 17 insertions, 14 deletions
@@ -12,17 +12,20 @@ export function addToggleBehaviour(list, description) { } } -// document.querySelector("#player-load input[type=file]").onchange = () => { -// if (fileInput.files.length > 0) { -// const file = fileInput.files[0]; -// if (file) { -// const reader = new FileReader(); -// reader.onload = function(e) { -// const content = e.target.result; -// regulars = csvToPlayers(content); -// addToggleBehaviour(regulars, "regular_"); -// }; -// reader.readAsText(file); -// } -// } -// }
\ No newline at end of file +export function getMatchCount(regulars, courts) { + const activeCourts = courts.filter(function (c) { return c.status }); + console.log("There are a total of " + activeCourts.length + " courts available."); + const activePlayers = regulars.filter(function (p) { return p.status;}); + console.log("There are a total of " + activePlayers.length + " players available."); + var possibleMatches = Math.floor(activePlayers.length / 4); + possibleMatches = possibleMatches > activeCourts.length ? activeCourts.length : possibleMatches; + return possibleMatches; +} + +export function shuffle(array) { + for (let i = array.length - 1; i > 0; i--) { + const j = Math.floor(Math.random() * (i + 1)); + [array[i], array[j]] = [array[j], array[i]]; + } + return array; +}
\ No newline at end of file |
