File tree Expand file tree Collapse file tree 2 files changed +10
-19
lines changed
exercises/graduated_tiered_prices/solutions/adrianliz/src Expand file tree Collapse file tree 2 files changed +10
-19
lines changed Original file line number Diff line number Diff line change @@ -19,19 +19,15 @@ export default class GraduatedTier {
19
19
return subscriptions >= this . to ;
20
20
}
21
21
22
- totalFor ( subscriptions : number ) : number {
23
- if ( this . covers ( subscriptions ) ) {
24
- return this . total ( ) ;
25
- }
26
-
27
- if ( subscriptions < this . from ) {
28
- return 0 ;
29
- }
22
+ reaches ( subscriptions : number ) : boolean {
23
+ return subscriptions >= this . from ;
24
+ }
30
25
31
- return ( subscriptions - this . from + 1 ) * this . price ;
26
+ numberOfSubscriptionsInside ( subscriptions : number ) : number {
27
+ return subscriptions - this . from + 1 ;
32
28
}
33
29
34
- totalFor2 ( subscriptions : Subscriptions ) : number {
30
+ totalFor ( subscriptions : Subscriptions ) : number {
35
31
if ( subscriptions . covers ( this ) ) {
36
32
return this . total ( ) ;
37
33
}
Original file line number Diff line number Diff line change @@ -9,23 +9,18 @@ export default class Subscriptions {
9
9
}
10
10
11
11
priceFor ( tiers : GraduatedTier [ ] ) : number {
12
- // return tiers.reduce(
13
- // (total, tier) => total + tier.totalFor(this.subscriptions),
14
- // 0
15
- // );
16
-
17
- return tiers . reduce ( ( total , tier ) => total + tier . totalFor2 ( this ) , 0 ) ;
12
+ return tiers . reduce ( ( total , tier ) => total + tier . totalFor ( this ) , 0 ) ;
18
13
}
19
14
20
15
covers ( tier : GraduatedTier ) : boolean {
21
- return false ;
16
+ return tier . covers ( this . subscriptions ) ;
22
17
}
23
18
24
19
reaches ( tier : GraduatedTier ) : boolean {
25
- return false ;
20
+ return tier . reaches ( this . subscriptions ) ;
26
21
}
27
22
28
23
numberOfSubscriptionsInTier ( tier : GraduatedTier ) : number {
29
- return 0 ;
24
+ return tier . numberOfSubscriptionsInside ( this . subscriptions ) ;
30
25
}
31
26
}
You can’t perform that action at this time.
0 commit comments