Hello, so I passed the test using switch statements, but I am curious to know. What would be an efficient way to solve this same problem if lets say there is more special characters and writing switch statements just becomes to lengthy? Would if statements be better? My curiosity is getting the better of me here. I’m interested because those switch statements or if statements could very will take the program longer to check each statement.
Summary
function convertHTML(str) {
return str.replace(/[&<>"']/g, function(character) {
switch (character) {
case '&':
return '&'
case '<':
return '<'
case '>':
return '>'
case '"':
return '"'
case "'":
return '''
default:
return character;
}
});
}
console.log(convertHTML("Dolce & Gabbana"));