blob: 308bba83f77f7c2077803ee3644f07e340cb89fe (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
export function addToggleBehaviour(list, description) {
let renderedHTML = list.map((i) => {return i.render();}).join('');
let listId = description + 'list';
document.getElementById(listId).innerHTML = renderedHTML;
for (let index = 0; index < list.length; ++index) {
const p = document.getElementById(description + list[index].id);
p.addEventListener("click", () => {
list[index].toggle();
p.classList.toggle('is-success');
p.classList.toggle('is-danger');
});
}
}
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;
}
|