-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path10-4-plumages.js
102 lines (90 loc) Β· 1.84 KB
/
10-4-plumages.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/**
* p368 μμ
*/
class Bird {
constructor(birdObject) {
Object.assign(this, birdObject);
}
get plumage() {
return 'μ μ μλ€';
}
get airSpeedVelocity() {
return null;
}
}
function plumages(birds) {
return new Map(
birds.map((b) => createBird(b)).map((bird) => [bird.name, bird.plumage])
);
}
function speeds(birds) {
return new Map(
birds
.map((b) => createBird(b))
.map((bird) => [bird.name, bird.airSpeedVelocity])
);
}
function createBird(bird) {
switch (bird.type) {
case 'μ λ½ μ λΉ':
return new EuropeanSwallow(bird);
case 'μν리카 μ λΉ':
return new AfricanSwallow(bird);
case 'λ
Έλ₯΄μ¨μ΄ νλ μ΅λ¬΄':
return new NorwegianBlueParrot(bird);
default:
return new Bird(bird);
}
}
class EuropeanSwallow extends Bird {
get plumage() {
return '보ν΅μ΄λ€';
}
get airSpeedVelocity() {
return 35;
}
}
class AfricanSwallow extends Bird {
get plumage() {
return this.numberOfCoconuts > 2 ? 'μ§μ³€λ€' : '보ν΅μ΄λ€';
}
get airSpeedVelocity() {
return 40 - 2 * this.numberOfCoconuts;
}
}
class NorwegianBlueParrot extends Bird {
get plumage() {
return this.voltage > 100 ? 'κ·Έμλ Έλ€' : 'μμλ€';
}
get airSpeedVelocity() {
return this.isNailed ? 0 : 10 + this.voltage / 10;
}
}
/**
* μμ μ€νμ μν μμμ μ½λ
*/
const birds = [
{
name: 'μ λ½ μ λΉ',
type: 'μ λ½ μ λΉ',
numberOfCoconuts: 2,
voltage: 0,
isNailed: false,
},
{
name: 'μν리카 μ λΉ',
type: 'μν리카 μ λΉ',
numberOfCoconuts: 2,
voltage: 0,
isNailed: false,
},
{
name: 'μ΅λ¬΄',
type: 'λ
Έλ₯΄μ¨μ΄ νλ μ΅λ¬΄',
numberOfCoconuts: 2,
voltage: 0,
isNailed: false,
},
];
console.log(plumages(birds));
console.log(speeds(birds));