Skip to content

Instantly share code, notes, and snippets.

@huytd
Created March 17, 2020 19:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save huytd/b30cc8d2a2962f5adcfa87c1a45b3bb9 to your computer and use it in GitHub Desktop.
Save huytd/b30cc8d2a2962f5adcfa87c1a45b3bb9 to your computer and use it in GitHub Desktop.
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