Created
September 30, 2021 13:02
-
-
Save AlixShahid/d0f3336e85b0a4574c8a8f54c8c06583 to your computer and use it in GitHub Desktop.
Mentoring challenge 1, by McLarenCollege
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 backspace(str, symbol) { | |
| let result = [] | |
| for ( let i=0; i<str.length; i++ ) { | |
| chr = (str[i]) | |
| if ( chr == symbol ) { | |
| result.pop() | |
| } else { | |
| result.push(chr) | |
| } | |
| } | |
| return result.join('') | |
| } | |
| ans = backspace("abc#d##c", "#") | |
| console.log(ans) | |
| ans = backspace("abc##d######", "#") | |
| console.log(ans) | |
| ans = backspace("#######", "#") | |
| console.log(ans) | |
| ans = backspace("", "#") | |
| console.log(ans) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment