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 {
1919 return subscriptions >= this . to ;
2020 }
2121
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+ }
3025
31- return ( subscriptions - this . from + 1 ) * this . price ;
26+ numberOfSubscriptionsInside ( subscriptions : number ) : number {
27+ return subscriptions - this . from + 1 ;
3228 }
3329
34- totalFor2 ( subscriptions : Subscriptions ) : number {
30+ totalFor ( subscriptions : Subscriptions ) : number {
3531 if ( subscriptions . covers ( this ) ) {
3632 return this . total ( ) ;
3733 }
Original file line number Diff line number Diff line change @@ -9,23 +9,18 @@ export default class Subscriptions {
99 }
1010
1111 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 ) ;
1813 }
1914
2015 covers ( tier : GraduatedTier ) : boolean {
21- return false ;
16+ return tier . covers ( this . subscriptions ) ;
2217 }
2318
2419 reaches ( tier : GraduatedTier ) : boolean {
25- return false ;
20+ return tier . reaches ( this . subscriptions ) ;
2621 }
2722
2823 numberOfSubscriptionsInTier ( tier : GraduatedTier ) : number {
29- return 0 ;
24+ return tier . numberOfSubscriptionsInside ( this . subscriptions ) ;
3025 }
3126}
You can’t perform that action at this time.
0 commit comments