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!
Top comments (20)
Rust:
Too easy...
Maybe
match ch
:vWhy?
Just to show off
Scala
JavaScript with regex:
Try with
Thanks. Fixt.
Progress 4GL
Classic use case for a stack (Python).
A quick Clojure solution, leveraging a (linked) list as a stack:
JavaScript
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!
Here is a ugly Python one-liner using
lambda
.Use Python 3.8
Idea is based on
PHP: