Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.