Created
December 29, 2019 05:19
-
-
Save risingBirdSong/d21ce7b5317855a97a018e4909ebf9de to your computer and use it in GitHub Desktop.
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
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