/
3_20.js
43 lines (34 loc) · 804 Bytes
/
3_20.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
class Gear {
constructor(chainring, cog, rim, tire) {
this._chainring = chainring;
this._cog = cog;
this._rim = rim;
this._tire = tire;
}
get chainring() { return this._chainring; }
get cog() { return this._cog; }
get rim() { return this._rim; }
get tire() { return this._tire; }
gear_inches() {
return this.ratio() * this.wheel.diameter();
}
get wheel() {
return new Wheel(this.rim, this.tire);
}
ratio() {
return this.chainring / this.cog;
}
}
class Wheel {
constructor(rim, tire) {
this._rim = rim;
this._tire = tire;
}
get rim() { return this._rim; }
get tire() { return this._tire; }
diameter() {
return this.rim + (this.tire * 2);
}
}
console.log(new Gear(52, 11, 26, 1.5).gear_inches());
// => 137.0909090909091