var sameString = function(str1,str2) {
let p1 = str1.length-1;
let p2 = str2.length-1;
while (p1 >= 0 || p2 >= 0) {
if (str1[p1] === "#" || str2[p2] === "#") {
if (str1[p1] === "#") {
let backCount = 2;
while (backCount > 0) {
p1--;
backCount--;
if (str1[p1] === "#") {
backCount += 2;
}
}
}
if (str2[p2] === "#") {
let backCount = 2;
while (backCount > 0) {
p2--;
backCount--;
if (str2[p2] === "#") {
backCount += 2;
}
}
}
} else {
if (str1[p1] !== str2[p2]) {
return false;
} else {
p1--;
p2--;
}
}
}
return true;
}
console.log(sameString('cb#had','chad'));
console.log(sameString('chs#ad','cb#had')); //f
console.log(sameString('chs#ad','cb#hs#ap#d'));
console.log(sameString('chs#ad','ce#b#hs#ap#d'));
console.log(sameString("c#d#","ab##")); //f
console.log(sameString('chad','cb#had'));
console.log(sameString('cb#had','chs#ad'));
console.log(sameString('cb#hs#ap#d','chs#ad'));
console.log(sameString('ce#b#hs#ap#d','chs#ad'));
console.log(sameString("ab##","c#d#")); //f