Last active
November 12, 2018 19:55
-
-
Save raganwald/48ded34b9411211f8752f396fd497cea to your computer and use it in GitHub Desktop.
Ridiculously Simple Balanced Parentheses Algorithm
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
function isBalancedSimple (before) { | |
if (before === '') return true; | |
const after = before.replace('()',''); | |
return (before !== after) && isBalancedSimple(after); | |
} | |
function isBalancedMultiple (before) { | |
if (before === '') return true; | |
const after = before.replace('()','').replace('[]','').replace('{}',''); | |
return (before !== after) && isBalancedMultiple(after); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment