Created
January 10, 2017 18:03
-
-
Save josenaves/d9f82387d5ecc07d0bb739a5cf60b9b4 to your computer and use it in GitHub Desktop.
Revisions
-
josenaves created this gist
Jan 10, 2017 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,14 @@ function balancedParentesis(string) { return !string.split("").reduce(function(previous, char) { if (previous < 0) return previous; if (char === "(") return previous + 1; if (char === ")") return previous - 1; return previous; }, 0); } balancedParentesis("))(("); // False balancedParentesis(")"); // False balancedParentesis("()"); // True