Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 38e1fd2

Browse files
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‎

Lines changed: 11 additions & 1 deletion
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‎

Lines changed: 11 additions & 1 deletion
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
### **...**
Lines changed: 11 additions & 0 deletions
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)

AltStyle によって変換されたページ (->オリジナル) /