Created
March 17, 2020 19:01
-
-
Save huytd/b30cc8d2a2962f5adcfa87c1a45b3bb9 to your computer and use it in GitHub Desktop.
This file contains 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 solve = (s, d) => { | |
// Write your code here | |
let word = ""; | |
let words = []; | |
let del = []; | |
let i = 0; | |
while (i < s.length) { | |
if (d.indexOf(s[i]) === -1) { | |
word += s[i]; | |
i++; | |
} else { | |
words.push(word); | |
word = []; | |
let dd = ""; | |
while (d.indexOf(s[i]) !== -1) { | |
dd += s[i]; | |
i++; | |
} | |
del.push(dd); | |
} | |
} | |
if (word.length) { | |
words.push(word); | |
} | |
del.reverse(); | |
let result = ""; | |
while (words.length || del.length) { | |
result += words.pop() || ""; | |
result += del.pop() || ""; | |
} | |
return result; | |
}; | |
debug(solve("hello//world:here", ["/", ":"])); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment