-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilter.js
31 lines (29 loc) · 1022 Bytes
/
filter.js
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
//The actual program
var indexToSection = function(classList, index) {
return classList[index.classIdx].sections[index.sectionIdx];
}
//path :: [{classIdx, sectionIdx}]
//curr :: {classIdx, sectionIdx}
//classList :: [{[{Section}]}]
//foundpaths :: [[{classIdx, sectionIdx}]]
function findSchedules(path, curr, classList, foundpaths) {
if (curr.classIdx === classList.length - 1) {
path.push(curr);
foundpaths.push(path);
}
else {
for (var s = {classIdx: curr.classIdx + 1, sectionIdx: 0};
s.sectionIdx < classList[curr.classIdx + 1].sections.length;
s.sectionIdx++) {
var sectionToCheck = indexToSection(classList, s);
if (!conflict(indexToSection(classList, curr), sectionToCheck) &&
path.every(function pathTestConf (element) {
return !conflict(indexToSection(classList, element),
sectionToCheck);
})) {
path.push(curr);
findSchedules(path, s, classList, foundpaths);
}
}
}
}