Hi, there are a couple of test cases that do not pass with my current code:
- The case where there are multiple occurrences of the same entities in a given string
- Inner double quotes
Here is my code so far:
function convertHTML(str) {
const strSplit = str.split('')
var indexOf = ''
var newStr = []
for (let i=0; i<strSplit.length; i++) {
if (strSplit[i] == '&') {
indexOf = str.indexOf('&');
strSplit.splice(indexOf,1,'&');
}
if (strSplit[i].match('\'.*?')) {
indexOf = str.indexOf(strSplit[i].match('\'.*?'));
strSplit.splice(indexOf,1,''');
}
if (strSplit[i] == '<') {
indexOf = str.indexOf('<');
strSplit.splice(indexOf,1,'<');
}
if (strSplit[i] == '>') {
indexOf = str.indexOf('>');
strSplit.splice(indexOf,1,'>');
}
if (strSplit[i].match('\".*?')) {
indexOf = str.indexOf(strSplit[i].match('\".*?'));
strSplit.splice(indexOf,1,'"');
}
else {
newStr.push(strSplit[i]);
}
}
return newStr.join('');
}
Test cases that fail:
-
convertHTML("Hamburgers < Pizza < Tacos")
results inHamburgers < Pizza < Tacos
-
convertHTML('Stuff in "quotation marks"')
outputsStuff in quotation marks