-
Notifications
You must be signed in to change notification settings - Fork 0
/
FA19.html
66 lines (56 loc) · 1.58 KB
/
FA19.html
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<script>
async function main() {
const URL = 'https://docs.google.com/spreadsheets/d/e/2PACX-1vTdxBuRHMXxMntXMRf91xYVnJsxZMAUM2nwFo-KJih_ADMcV3ePxeQLCo35xtXBLmu6_byQ0tzjP58f/pub?output=csv'
var request = await fetch(URL);
var text = await request.text();
var data = [];
for (let line of text.split('\n')) {
data.push(line.split(','))
}
header = data[0];
var teams = [];
for(var i = 1 ; i < header.length ; i++) {
teams.push(header[i].replace(/(\r\n|\n|\r)/gm,""));
}
var directory = [];
for(var row = 1; row < data.length ; row++) {
var value = Math.random();
for (var col = 1 ; col < data[0].length ; col++ ) {
if (data[row][col] == 1) {
value += 1;
}
}
directory[value] = data[row][0];
}
console.log(directory);
var keys = Object.keys(directory).sort().reverse();
console.log(keys);
var team1 = [];
var team2 = [];
var result = [team1, team2];
var space = [17,15];
function add(a, b) {
return a + b;
}
var counter = 0;
while(space.reduce(add,0) > 0) {
var team = Math.floor(Math.random() * 2);
while (space[team] == 0) {
team = Math.floor(Math.random() * 2);
}
result[team].push(directory[keys[counter]]);
space[team] -= 1;
counter += 1;
}
console.log(result);
document.write('<pre>');
for (var i = 0 ; i < teams.length ; i++) {
document.write("\n" + teams[i] + ": ");
for (var j = 0 ; j < result[i].length ; j++) {
document.write("\n"+ result[i][j]);
}
}
document.write('</pre>');
}
document.addEventListener("DOMContentLoaded", main);
</script>