diff --git a/solution/1400-1499/1410.HTML Entity Parser/README.md b/solution/1400-1499/1410.HTML Entity Parser/README.md index c44cf338360c8..ea713290133ae 100644 --- a/solution/1400-1499/1410.HTML Entity Parser/README.md +++ b/solution/1400-1499/1410.HTML Entity Parser/README.md @@ -182,6 +182,24 @@ public: }; ``` +### **TypeScript** + +```ts +function entityParser(text: string): string { + const d: { [key: string]: string } = { + '"': '"', + ''': "'", + '&': '&', + '>': '>', + '<': '<', + '⁄': '/', + }; + + const pattern = new RegExp(Object.keys(d).join('|'), 'g'); + return text.replace(pattern, match => d[match]); +} +``` + ### **...** ``` diff --git a/solution/1400-1499/1410.HTML Entity Parser/README_EN.md b/solution/1400-1499/1410.HTML Entity Parser/README_EN.md index 442bd7f14912c..2f05d08cce4ab 100644 --- a/solution/1400-1499/1410.HTML Entity Parser/README_EN.md +++ b/solution/1400-1499/1410.HTML Entity Parser/README_EN.md @@ -151,6 +151,24 @@ public: }; ``` +### **TypeScript** + +```ts +function entityParser(text: string): string { + const d: { [key: string]: string } = { + '"': '"', + ''': "'", + '&': '&', + '>': '>', + '<': '<', + '⁄': '/', + }; + + const pattern = new RegExp(Object.keys(d).join('|'), 'g'); + return text.replace(pattern, match => d[match]); +} +``` + ### **...** ``` diff --git a/solution/1400-1499/1410.HTML Entity Parser/Solution.ts b/solution/1400-1499/1410.HTML Entity Parser/Solution.ts new file mode 100644 index 0000000000000..7fb46770b455a --- /dev/null +++ b/solution/1400-1499/1410.HTML Entity Parser/Solution.ts @@ -0,0 +1,13 @@ +function entityParser(text: string): string { + const d: { [key: string]: string } = { + '"': '"', + ''': "'", + '&': '&', + '>': '>', + '<': '<', + '⁄': '/', + }; + + const pattern = new RegExp(Object.keys(d).join('|'), 'g'); + return text.replace(pattern, match => d[match]); +}