Trying to compare to arrays in JavaScript with the following approach.
return stack1.forEach((v, i) => v === stack2[i]);
I want to get it working but it is returning undefined instead of true or false if the arrays are the same.
Here is the full code:
const backspace_compare = function(str1, str2) {
let stack1 = [];
let stack2 = [];
for (let i = 0; i < str1.length; i++) {
str1[i] === "#" ? stack1.pop() : stack1.push(str1[i]);
}
for (let i = 0; i < str1.length; i++) {
str2[i] === "#" ? stack2.pop() : stack2.push(str2[i]);
}
return stack1.forEach((v, i) => v === stack2[i]);
};
Any help to fix the way I'm comparing the arrays using a similar approach would be really appreciated.