From c3603b9b810926623a4b190b1595a71e5a352dff Mon Sep 17 00:00:00 2001 From: thinkasany <480968828@qq.com> Date: Thu, 23 Nov 2023 01:13:38 +0800 Subject: [PATCH] feat: add ts solution to lc problem: No.1410 --- .../1410.HTML Entity Parser/README.md | 18 ++++++++++++++++++ .../1410.HTML Entity Parser/README_EN.md | 18 ++++++++++++++++++ .../1410.HTML Entity Parser/Solution.ts | 13 +++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 solution/1400-1499/1410.HTML Entity Parser/Solution.ts 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]); +}