File tree 2 files changed +38
-0
lines changed
2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change 148
148
1380|[ Lucky Numbers in a Matrix] ( ./1380-lucky-numbers-in-a-matrix.js ) |Easy|
149
149
1389|[ Create Target Array in the Given Order] ( ./1389-create-target-array-in-the-given-order.js ) |Easy|
150
150
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|
151
152
1436|[ Destination City] ( ./1436-destination-city.js ) |Easy|
152
153
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|
153
154
1446|[ Consecutive Characters] ( ./1446-consecutive-characters.js ) |Easy|
Original file line number Diff line number Diff line change
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 < and symbol character is <.
15
+ * - Slash: the entity is ⁄ 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
+ '"' : '"' ,
29
+ ''' : '\'' ,
30
+ '&' : '&' ,
31
+ '>' : '>' ,
32
+ '<' : '<' ,
33
+ '⁄' : '/'
34
+ } ;
35
+
36
+ return text . replace ( new RegExp ( Object . keys ( map ) . join ( '|' ) , 'g' ) , m => map [ m ] ) ;
37
+ } ;
You can’t perform that action at this time.
0 commit comments