Skip to content

Instantly share code, notes, and snippets.

@bernbecht
Last active January 23, 2017 16:31
Show Gist options
  • Save bernbecht/649fba1d4c464d0885b192d641ce9b96 to your computer and use it in GitHub Desktop.
Save bernbecht/649fba1d4c464d0885b192d641ce9b96 to your computer and use it in GitHub Desktop.
braces/brackets/parentheses validator without order checking
var openingSymbols = ['{', '[', '('],
closingSymbols = ['}', ']', ')'],
counter = 0;
function scopeValidator(char) {
if (openingSymbols.indexOf(char) != -1) counter++;
else if (closingSymbols.indexOf(char) != -1) counter--;
}
function scopeParser(text) {
counter = 0;
for(var i=0; i <= text.length; i++) {
scopeValidator(text[i]);
}
if(counter==0) return true;
return false;
}
scopeParser("{ [ ] ( ) }");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment