Created
April 6, 2022 03:16
Cassidy Williams - question of the week 2021-04-04
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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