Skip to content

Instantly share code, notes, and snippets.

@g-bel
Created April 6, 2022 03:16
Show Gist options
  • Save g-bel/2f535e889d9fd568fe4904cbbcf31675 to your computer and use it in GitHub Desktop.
Save g-bel/2f535e889d9fd568fe4904cbbcf31675 to your computer and use it in GitHub Desktop.
Cassidy Williams - question of the week 2021-04-04
const equalWithDeletions = (strOne, strTwo) => {
console.log('Result: ', cleanStr(strOne) === cleanStr(strTwo));
};
const cleanStr = (str) => {
let text = str;
while (text.includes('#') || text.includes('%')) {
const hash = text.indexOf('#');
const amp = text.lastIndexOf('%');
if (hash >= 0 && ((amp >= 0 && hash < amp) || amp < 0)) {
text = text.replace(/.?#/, '');
} else {
text = text.substring(0, amp) + text.substring(amp + 2);
}
}
console.log(`"${str}" became: "${text}"`);
return text;
}
console.log('Example 1:');
equalWithDeletions("a##x", "#a#x");
console.log('\nExample 2:');
equalWithDeletions("fi##f%%%th %%year #time###", "fifth year time");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment