Last active
January 23, 2017 16:31
-
-
Save bernbecht/649fba1d4c464d0885b192d641ce9b96 to your computer and use it in GitHub Desktop.
braces/brackets/parentheses validator without order checking
This file contains 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
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