I want to write a function to test if a string such as "(())" or "<<>>" is equal on both sides if they were reversed. where as something like "((()" would be false
Is there a name for something like this? I assume is a common algorithm.
For some reason, reverse doesn't do anything on right after splitting it into an array?
function ifEqual(str) {
let left = str.slice(0, str.length / 2);
let right = str.slice(str.length / 2).split("").reverse().join("");
console.log(left);
console.log(right);
return left === right;
}
ifEqual("(())")
<><<>>okay? is<><>okay? Will only characters that have "flips" be used?{"<": ">", "(": ")", ...}. Then you can loop over the characters in the string and check whether they match their partner.reversereverses the array. What you're doing in the second line of the function is to take "))" and splitting it into an array [")", ")"], then reversing this array, which is [")", ")"]. Reverse does not "reverse" the string characters to it's conceptual counterparts. Hope this helps you on the right track (or perhaps off the wrong one at least).