-
Notifications
You must be signed in to change notification settings - Fork 0
/
stringmapjoin.ts
41 lines (32 loc) · 994 Bytes
/
stringmapjoin.ts
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
// Starts with this
buildFeaturePreview(vehicle: IVehicle): string {
let featureList: string[] = [];
let features: string = '';
if (this.shouldShowMpg(vehicle)) {
featureList.push(`${vehicle.MPGCity} / ${vehicle.MPGHighway} MPG`);
}
vehicle.HighlightedFeatures
.map(feature => {
featureList.push(`${feature.description}`);
});
features = featureList.join(', ');
features += '...';
return features;
}
shouldShowMpg(vehicle: IVehicle): boolean {
return (
vehicle &&
(vehicle.MPGCity && vehicle.MPGCity !== 0) &&
(vehicle.MPGHighway && vehicle.MPGHighway !== 0)
);
}
//Refactored
buildFeaturePreview(vehicle: IVehicle): string {
let mpg = this.shouldShowMpg(vehicle) ? `${vehicle.MPGCity} / ${vehicle.MPGHighway} MPG` : null;
let features = vehicle.HighlightedFeatures.map(feature => feature.description);
return [mpg,
...features]
.filter(cmp.isDefinedAndNotNull)
.join(', ') +
'...';
}