Skip to content

Commit 85034d7

Browse files
authored
feat: add ts solution to lc problem: No.1410 (doocs#2001)
1 parent 5610d9e commit 85034d7

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

solution/1400-1499/1410.HTML Entity Parser/README.md

+18
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,24 @@ public:
182182
};
183183
```
184184
185+
### **TypeScript**
186+
187+
```ts
188+
function entityParser(text: string): string {
189+
const d: { [key: string]: string } = {
190+
'"': '"',
191+
''': "'",
192+
'&': '&',
193+
'>': '>',
194+
'&lt;': '<',
195+
'&frasl;': '/',
196+
};
197+
198+
const pattern = new RegExp(Object.keys(d).join('|'), 'g');
199+
return text.replace(pattern, match => d[match]);
200+
}
201+
```
202+
185203
### **...**
186204

187205
```

solution/1400-1499/1410.HTML Entity Parser/README_EN.md

+18
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,24 @@ public:
151151
};
152152
```
153153
154+
### **TypeScript**
155+
156+
```ts
157+
function entityParser(text: string): string {
158+
const d: { [key: string]: string } = {
159+
'&quot;': '"',
160+
'&apos;': "'",
161+
'&amp;': '&',
162+
'&gt;': '>',
163+
'&lt;': '<',
164+
'&frasl;': '/',
165+
};
166+
167+
const pattern = new RegExp(Object.keys(d).join('|'), 'g');
168+
return text.replace(pattern, match => d[match]);
169+
}
170+
```
171+
154172
### **...**
155173

156174
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
function entityParser(text: string): string {
2+
const d: { [key: string]: string } = {
3+
'&quot;': '"',
4+
'&apos;': "'",
5+
'&amp;': '&',
6+
'&gt;': '>',
7+
'&lt;': '<',
8+
'&frasl;': '/',
9+
};
10+
11+
const pattern = new RegExp(Object.keys(d).join('|'), 'g');
12+
return text.replace(pattern, match => d[match]);
13+
}

0 commit comments

Comments
 (0)