DEV Community

Discussion on: Backspace String Comparisons: Two Ways To Approach a Common Algorithm

Collapse
 
chety profile image
Chety • Edited

Hi Alisa,

Great series by the way thanks. Here is my solution. Maybe it helps someone else

function pureWord(word){
    return word.split('').reduce((pure,char,i) => {
        if(char === "#"){
            pure = word.slice(i + 1)
        }
        return pure;
    }, word)
}
var backspaceCompare = function(s, t) {
    return pureWord(s) === pureWord(t);
};
Enter fullscreen mode Exit fullscreen mode