Created
April 10, 2023 20:52
-
-
Save 7pulse/9d8a81d796af89b14a3f5e4843aa1847 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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