I have string 101000 or 1010100 in which I am trying to replace 100 recursively using function remove data. The function removedata should return "yes" when string is empty and "no" when string is not empty while replacing it with value 100.
It works fine for string 1010100. It returns "no" but not for string 101000 where it becomes empty.
console.log(removedata("1010100"));
console.log(removedata("101000"));
function removedata(data) {
data = data.replace("100", "");
if (data.length == 0) {
return "yes";
} else {
if (data.indexOf("100") > -1 && data.length > 0) {
removedata(data);
} else {
return "no";
}
}
}
when 1010100 it returns no but when 101000 it returns undefined
removedata(data)should bereturn removedata(data)data = data.replace(/100/g, "");"101000".replace(/100/g, "") == "100".