[JavaScript] Counter solution w/ explanation
The idea is that the result is easier to fill than to fill and cut, and since backspace removes previous values, then it\'s easier for us to turn it all around,
The idea is that the result is easier to fill than to fill and cut, and since backspace removes previous values, then it\'s easier for us to turn it all around, in other words, go from the end.\n\nSince there can be several backspaces in a row, we cannot delete previous values, and the best solution would be a counter that will count how many backspaces should be applied to ordinary characters.\n\nTo avoid repetition in the code, one function was written that applied the same editing method for both inputs.\n\n```javascript\nconst backspaceCompare = (S, T) => { \n    return edit(S) === edit(T);\n    \n    function edit(str) {\n        let result = \'\';\n        let backspaces = 0;\n        \n        for (let i = str.length - 1; i >= 0; i -= 1) {        \n            if (str[i] === \'#\') {\n                backspaces += 1;\n            } else if (backspaces > 0) {\n                backspaces -= 1;\n            } else {\n                result = str[i] + result;\n            }\n        }\n        \n        return result;\n    }\n};\n```
['JavaScript']