Skip to content

Commit b57247f

Browse files
committed
Add solution #1410
1 parent 15e28fa commit b57247f

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@
148148
1380|[Lucky Numbers in a Matrix](./1380-lucky-numbers-in-a-matrix.js)|Easy|
149149
1389|[Create Target Array in the Given Order](./1389-create-target-array-in-the-given-order.js)|Easy|
150150
1408|[String Matching in an Array](./1408-string-matching-in-an-array.js)|Easy|
151+
1410|[HTML Entity Parser](./1410-html-entity-parser.js)|Medium|
151152
1436|[Destination City](./1436-destination-city.js)|Easy|
152153
1437|[Check If All 1's Are at Least Length K Places Away](./1437-check-if-all-1s-are-at-least-length-k-places-away.js)|Easy|
153154
1446|[Consecutive Characters](./1446-consecutive-characters.js)|Easy|

solutions/1410-html-entity-parser.js

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* 1410. HTML Entity Parser
3+
* https://leetcode.com/problems/html-entity-parser/
4+
* Difficulty: Medium
5+
*
6+
* HTML entity parser is the parser that takes HTML code as input and replace all the
7+
* entities of the special characters by the characters itself.
8+
*
9+
* The special characters and their entities for HTML are:
10+
* - Quotation Mark: the entity is " and symbol character is ".
11+
* - Single Quote Mark: the entity is ' and symbol character is '.
12+
* - Ampersand: the entity is & and symbol character is &.
13+
* - Greater Than Sign: the entity is > and symbol character is >.
14+
* - Less Than Sign: the entity is &lt; and symbol character is <.
15+
* - Slash: the entity is &frasl; and symbol character is /.
16+
*
17+
* Given the input text string to the HTML parser, you have to implement the entity parser.
18+
*
19+
* Return the text after replacing the entities by the special characters.
20+
*/
21+
22+
/**
23+
* @param {string} text
24+
* @return {string}
25+
*/
26+
var entityParser = function(text) {
27+
const map = {
28+
'&quot;': '"',
29+
'&apos;': '\'',
30+
'&amp;': '&',
31+
'&gt;': '>',
32+
'&lt;': '<',
33+
'&frasl;': '/'
34+
};
35+
36+
return text.replace(new RegExp(Object.keys(map).join('|'), 'g'), m => map[m]);
37+
};

0 commit comments

Comments
 (0)