Assume "#" is like a backspace in string. This means that string "a#bc#d" would actually be "bd".
Implement a function that will process a string with "#" symbols and understand them as backspaces.
Examples
"abc#def##ghi###" ==> "abd"
"abc#d##c" ==> "ac"
"abc##d######" ==> ""
"#######" ==> ""
"" ==> ""
Tests
cleanString('abc#de##c')
cleanString('abc####dhh##c#')
cleanString('Thee# Empires# SS#tateBuildingg#')
Good Luck!
This challenge comes from vetalpaprotsky on CodeWars. Thank you to CodeWars, who has licensed redistribution of this challenge under the 2-Clause BSD License!
Want to propose a challenge idea for a future post? Email yo+challenge@dev.to with your suggestions!
Latest comments (20)
A quick Clojure solution, leveraging a (linked) list as a stack:
Progress 4GL
PHP:
Another JS solution
Haskell:
TypeScript
Here is a ugly Python one-liner using
lambda.Use Python 3.8
Idea is based on
Python – No doc strings etc., it's a challenge after all…
This is always a good idea to comment your code. Beginners trying to solve these challenges can learn a lot from veterans like you!
Scala
Hope this is right, C++