Skip to content

Commit 89209bd

Browse files
committed
feat(graduated-tiered-pricing): [tpp] 🟢 7. scalar → array
1 parent 205d0d5 commit 89209bd

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

exercises/graduated_tiered_prices/solutions/codely_triangulation-with-tpp/src/GraduatedTieredPricing.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ import { Tier } from "./Tier";
22

33
export class GraduatedTieredPricing {
44
for(subscriptions: number): number {
5-
const tier1 = new Tier(1, 2, 299);
6-
const tier2 = new Tier(3, 10, 239);
7-
const tier3 = new Tier(11, 25, 219);
5+
const tiers = [
6+
new Tier(1, 2, 299),
7+
new Tier(3, 10, 239),
8+
new Tier(11, 25, 219),
9+
new Tier(26, 50, 199),
10+
];
811

9-
return (
10-
tier1.totalFor(subscriptions) +
11-
tier2.totalFor(subscriptions) +
12-
tier3.totalFor(subscriptions)
13-
);
12+
return tiers.reduce((total: number, tier: Tier) => {
13+
return total + tier.totalFor(subscriptions);
14+
}, 0);
1415
}
1516
}

0 commit comments

Comments
 (0)