Also, I think the removeBackspaces method can further be reduced with reduce:
function removeBackspaces(arr) {
return arr.reduce((result, val) => {
val === '-B' ? result.pop() : result.push(val)
return result
}, [])
}
Gives me the same result, I think, and helps guard against typical problems introduced by loops, such as "off-by-one" errors. (array.reduce helps the iteration stay within the bounds of the array size)
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Also, I think the
removeBackspaces
method can further be reduced withreduce
:Gives me the same result, I think, and helps guard against typical problems introduced by loops, such as "off-by-one" errors. (
array.reduce
helps the iteration stay within the bounds of the array size)