Skip to content

Instantly share code, notes, and snippets.

@risingBirdSong
Created December 29, 2019 05:19
Show Gist options
  • Save risingBirdSong/d21ce7b5317855a97a018e4909ebf9de to your computer and use it in GitHub Desktop.
Save risingBirdSong/d21ce7b5317855a97a018e4909ebf9de to your computer and use it in GitHub Desktop.
function cleanString(s: string) {
let arrayed = s.split(''); //?
let index = 0;
while (index < arrayed.length) {
arrayed
if (arrayed[index] == "#") {
if (index == 0) {
arrayed.splice(index, 1);
index = 0;
continue;
}
arrayed.splice(index - 1, 2);
index = 0;
continue;
}
index++;
}
return arrayed.join('');
}
// it worked :), but here's a much better solution from another warrior =>
function clean_string(s) {
const result = []
for (const c of s) {
if (c === "#") {
result.pop()
} else {
result.push(c)
}
}
return result.join("")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment