-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathducktypium.js
54 lines (43 loc) · 1.3 KB
/
ducktypium.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
class Ducktypium {
constructor(color) {
if (color != "red" && color != "blue" && color != "yellow"){
throw new Error("Wrong color")
}
this.color = color;
}
calibrationSequence = []
refract(arg){
if (arg != "red" && arg != "blue" && arg != "yellow"){
throw new Error("Wrong color")
}
if (arg == this.color){
return this.color
}
else {
if (arg == "red" | this.color == "red"){
if (arg == "yellow" | this.color == "yellow") {
return "orange"
}
else {
return "purple"
}
}
else if (arg == "blue" | this.color == "blue"){
return "green"
}
}
}
calibrate(array){
array.sort()
for (var i in array) {
array[i] *= 3
}
this.calibrationSequence = array
}
}
const dt = new Ducktypium('red');
console.log(dt.color); // prints 'red'
console.log(dt.refract('blue')); // prints 'purple'
console.log(dt.refract('red')); // prints 'red'
dt.calibrate([3, 5, 1]);
console.log(dt.calibrationSequence); // prints [3, 9, 15]