I'm trying to replace a substring with the word 'denied'. For example: if the original string is "abcdefg" and sub-string to replace is "bcd", expected output is "aDENIEDefg".
I can't use .replace or anything else, just .substring
function replacer (variable, replace) {
for (let a = variable.length - 1; a >=0; a--) {
for (let b = replace.length - 1; b >= 0; b--) {
if (replace[b] === variable[a]) {
}
}
}
}
I have no clue what to do next.
Here is my code to just remove characters from a string.
let stringToReturn = original;
for (let a = toDelete.length - 1; a >= 0; a--) {
for (let b = original.length - 1; b >= 0; b--) {
if (original[b] === toDelete[a]) {
stringToReturn = stringToReturn.substring(0, b) + stringToReturn.substring(b + 1, stringToReturn.length);
} else {
continue;
}
}
}
alert(stringToReturn);
}
But this time I need not to just remove one characters, but find a sub-string to replace with DENIED. I apologize for the code style.
abcdefgbcd, should you getaDENIEDefgDENIEDoraDENIEDefgbcd???