Skip to content

Commit 38e1fd2

Browse files
committed
feat: add typescript solution to lc problem: No.2288
No.2288.Apply Discount to Prices
1 parent ea9a02c commit 38e1fd2

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

solution/2200-2299/2288.Apply Discount to Prices/README.md

+11-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,17 @@ class Solution {
114114
### **TypeScript**
115115

116116
```ts
117-
117+
function discountPrices(sentence: string, discount: number): string {
118+
const sell = (100 - discount) / 100;
119+
let reg = new RegExp(/^(\$)(([1-9]\d*\.?\d*)|(0\.\d*))$/g);
120+
let arr = sentence.split(' ').map(d => {
121+
if (!reg.test(d)) return d;
122+
return d.replace(reg, (s, $1, $2) => {
123+
return `$${(sell * $2).toFixed(2)}`;
124+
});
125+
});
126+
return arr.join(' ');
127+
};
118128
```
119129

120130
### **...**

solution/2200-2299/2288.Apply Discount to Prices/README_EN.md

+11-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,17 @@ class Solution {
103103
### **TypeScript**
104104

105105
```ts
106-
106+
function discountPrices(sentence: string, discount: number): string {
107+
const sell = (100 - discount) / 100;
108+
let reg = new RegExp(/^(\$)(([1-9]\d*\.?\d*)|(0\.\d*))$/g);
109+
let arr = sentence.split(' ').map(d => {
110+
if (!reg.test(d)) return d;
111+
return d.replace(reg, (s, $1, $2) => {
112+
return `$${(sell * $2).toFixed(2)}`;
113+
});
114+
});
115+
return arr.join(' ');
116+
};
107117
```
108118

109119
### **...**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
function discountPrices(sentence: string, discount: number): string {
2+
const sell = (100 - discount) / 100;
3+
let reg = new RegExp(/^(\$)(([1-9]\d*\.?\d*)|(0\.\d*))$/g);
4+
let arr = sentence.split(' ').map(d => {
5+
if (!reg.test(d)) return d;
6+
return d.replace(reg, (s, $1, $2) => {
7+
return `$${(sell * $2).toFixed(2)}`;
8+
});
9+
});
10+
return arr.join(' ');
11+
};

0 commit comments

Comments
 (0)