forked from keiichico/DIGIGIT
-
Notifications
You must be signed in to change notification settings - Fork 3
/
roomies.html
61 lines (50 loc) · 1.3 KB
/
roomies.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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Dorm Placment Generator</title>
</head>
<body>
<script>
// no gender mixing
var dorm_rooms = []; // 10 rooms (4-8 per room)
var boys = []; // 31
var girls = []; // 29
for(var i=0; i< 31; i++){
boys.push({
name: i,
room: null,
friends: getRandomFriends(i, 31)
})
}
boys.forEach(function(boy){
var count = 0;
boy.friends.forEach(function(friend){
var friend = boys[friend];
if( friend.friends.indexOf(boy.name) != -1){
count++;
}
});
console.log(boy.name, count);
})
function getRandomFriends(person, total){
var friends = []
, total_friends = getRandom(4) || 1
, i = 0;
while(i < total_friends ){
var f = getRandom(total);
if(f != person && friends.indexOf(f) != 1){
i++;
friends.push(f);
}
}
return friends;
}
function getRandom(num){
return Math.floor(Math.random()* num);
}
</script>
<input type="button" value="Populate Arrays" onclick="populate_arrays()" /> </br>
<input type="button" value="Generate Bestie Lists" onclick="generate_besties_list(0,30)" /> </br>
</body>
</html>