Skip to content

Instantly share code, notes, and snippets.

@raganwald
Last active November 12, 2018 19:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raganwald/48ded34b9411211f8752f396fd497cea to your computer and use it in GitHub Desktop.
Save raganwald/48ded34b9411211f8752f396fd497cea to your computer and use it in GitHub Desktop.
Ridiculously Simple Balanced Parentheses Algorithm
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