Skip to content

Instantly share code, notes, and snippets.

@7pulse
Created April 10, 2023 20:52
Show Gist options
  • Save 7pulse/9d8a81d796af89b14a3f5e4843aa1847 to your computer and use it in GitHub Desktop.
Save 7pulse/9d8a81d796af89b14a3f5e4843aa1847 to your computer and use it in GitHub Desktop.
let str = ")((()))()";
let count = 0;
function findMatch(str) {
if (str.includes("()")) {
let index = str.indexOf("()");
str = str.slice(0, index) + str.slice(index + 2);
count++;
findMatch(str);
} else {
console.log(count);
return;
}
}
findMatch(str);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment