Skip to content

Instantly share code, notes, and snippets.

@AlixShahid
Created September 30, 2021 13:02
Show Gist options
  • Select an option

  • Save AlixShahid/d0f3336e85b0a4574c8a8f54c8c06583 to your computer and use it in GitHub Desktop.

Select an option

Save AlixShahid/d0f3336e85b0a4574c8a8f54c8c06583 to your computer and use it in GitHub Desktop.
Mentoring challenge 1, by McLarenCollege
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