From 0e9e28c2595c1ec46d8601efa6f4d377ee70cb27 Mon Sep 17 00:00:00 2001 From: Karan Jayachandra Date: Tue, 11 Nov 2025 17:50:02 +0100 Subject: First version of proposal --- utils.mjs | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) (limited to 'utils.mjs') diff --git a/utils.mjs b/utils.mjs index 968731c..308bba8 100644 --- a/utils.mjs +++ b/utils.mjs @@ -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 -- cgit v1.3.1