guide: add code explanations to algorithm (#25816)

Added a code explanation for the beginner and intermediate code solutions of the 'convert-html-entities' algorithm, from the js certification
pull/35145/head
Kenny Zhou 2019-02-11 05:17:34 -06:00 committed by Manish Giri
parent c779246645
commit 342d8657a5
1 changed files with 8 additions and 2 deletions

View File

@ -71,7 +71,10 @@ title: Convert HTML Entities
```
### Code Explanation:
Explain solution here and add any relevant links
* Assign **temp** to `str.split('')`, which creates an array containing each individual character in the passed in string.
* Pass each character in the newly created array into a `switch()` statement.
* Replace the HTML entities with their corresponding HTML entity string (i.e. `'&'` becomes `'&'` in line 51)
* `temp.join('')` converts the array of characters into a string to be returned.
#### Relevant Links
@ -96,7 +99,10 @@ Explain solution here and add any relevant links
### Code Explanation:
Explain solution here and add any relevant links
* **str** is assigned to a new version of **str** that will contain the original string with all HTML entities converted
* The **first parameters** in `replace()` contains a regular expression that matches all instances of each HTML entity in **str**
* Replace all those instances with the corresponding HTML strings given in the **second parameter** of `replace()`
* Finally, the new **str** is returned
#### Relevant Links