Created
January 10, 2021 14:27
-
-
Save sebastianherman/e609fb45fb70dc3e21a55bf2e93b5800 to your computer and use it in GitHub Desktop.
Intermediate Algorithm Scripting: Convert HTML Entities - freeCodeCamp solution
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 convertHTML(str) { | |
let signs = {'&': '&', | |
'<': '<', | |
'>': '>', | |
'\"': '"', | |
'\'': '''}; | |
let signKeys = Object.keys(signs); | |
console.log(signKeys); | |
let strArr = str.split(/([&<>"'])/g); | |
console.log(strArr); | |
return strArr.map(word => { | |
if (signKeys.includes(word)) { | |
return signs[word]; | |
} else { | |
return word; | |
} | |
}).join(""); | |
} | |
console.log(convertHTML("Dolce & Gabbana")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment