Skip to content

Instantly share code, notes, and snippets.

@ramazankanbur
Created November 10, 2019 15:38
Show Gist options
  • Save ramazankanbur/6227eb5f79354c7366dded49fc6c8b6e to your computer and use it in GitHub Desktop.
Save ramazankanbur/6227eb5f79354c7366dded49fc6c8b6e to your computer and use it in GitHub Desktop.
function balancedParens(string){
return !string.split("").reduce(function(previous, char){
if(previous < 0) { return previous; }
if(char === "(") { return ++previous; }
if(char === ")") { return --previous; }
return previous;
}, 0);
}
balancedParens("(()()())()");
//output
true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment