Created
May 27, 2019 15:05
-
-
Save bartcis/a99ebf3a8859e9cfbdea69f467a18c29 to your computer and use it in GitHub Desktop.
HTML entities converter - solution 2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function convertHTMLInt(string) { | |
| // 1. Use build in replace method and RegExp to change characters | |
| return string | |
| .replace(/&/g, '&') | |
| .replace(/</g, '<') | |
| .replace(/>/g, '>') | |
| .replace(/"/g, '"') | |
| .replace(/'/g, '''); | |
| } | |
| console.time('Start Algo 2'); | |
| console.log(convertHTMLInt(`>I love 'Rock & Roll'<`)); | |
| console.timeEnd('Start Algo 2'); // Start Algo 2: 0.35009765625ms |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment