-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrunAmd.js
67 lines (63 loc) · 2.19 KB
/
runAmd.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
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
67
var definitions = [];
var define = function(name, requirements, f) {
definitions.push({
name: name,
requirements: requirements.slice(2),
execute: f
});
};
var startApp = function() {
var registeredModules = {
'std/CodinGame': {
readline: readline,
print: print,
printErr: printErr
}
};
var canBeRegistered = function(requirements) {
for (var idx = 0 ; idx !== requirements.length ; ++idx) {
if (!registeredModules.hasOwnProperty(requirements[idx]))
return false;
}
return true;
};
while (true) {
let registeredOne = false;
for (var idx = 0 ; idx !== definitions.length ; ++idx) {
var def = definitions[idx];
if (registeredModules.hasOwnProperty(def.name)) continue;
if (!canBeRegistered(def.requirements)) continue;
registeredOne = true;
printErr('Registration of ' + def.name);
var registration = {};
var params = [null, registration];
for (var rid = 0 ; rid !== def.requirements.length ; ++rid) {
params.push(registeredModules[def.requirements[rid]]);
}
def.execute.apply(/*this*/null, params);
registeredModules[def.name] = registration;
printErr('Registration done');
}
if (!registeredOne) {
printErr('Following modules cannot be registered properly:');
for (const def of definitions) {
if (registeredModules.hasOwnProperty(def.name)) continue;
const missingRequirements = def.requirements.filter(n => !registeredModules.hasOwnProperty(n));
printErr(`- ${def.name} has missing dependencies ${JSON.stringify(missingRequirements)}`);
}
throw 'Unable to register';
}
}
};
// YOUR CODE HERE
// YOUR CODE HERE
// YOUR CODE HERE
// YOUR CODE HERE
// YOUR CODE HERE
// Copy-paste the content of lib/bundle.js here
// YOUR CODE HERE
// YOUR CODE HERE
// YOUR CODE HERE
// YOUR CODE HERE
// YOUR CODE HERE
startApp();