From dcb5af87fbff3fb01c8d91b7a1902a76003f21b6 Mon Sep 17 00:00:00 2001 From: Daniel Shin Date: Fri, 3 Feb 2017 10:52:31 -0700 Subject: [PATCH 1/2] submit solution --- solution.js | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 solution.js diff --git a/solution.js b/solution.js new file mode 100644 index 0000000..76e6522 --- /dev/null +++ b/solution.js @@ -0,0 +1,46 @@ +class StringValidator{ + constructor(){ + this.pairs = { "[": "]", "{": "}" } + } + // loop through array + // get first pair + // see if second exists + // if does exit + // else return false + + validate(string){ + var stringArray = string.split(""); + var answer; + var bcount = 0; + var hcount = 0; + var pcount = 0; + var falseAnswer; + + for(var i = 0; i < stringArray.length; i++){ + var current = stringArray[i]; + if(current == "("){ pcount += 1; } + if(current == "["){ bcount += 1; } + if(current == "{"){ hcount += 1; } + + for(var j = 0 + 1; j < stringArray.length; j++){ + var newItem = stringArray[j]; + if(current == "(" && newItem == ")") + if(current == "(" && newItem == ")"){ pcount += 1; } + if(current == "[" && newItem == "]"){ bcount += 1; } + if(current == "{" && newItem == "}"){ hcount += 1; } + } + } + + if((pcount % 2 != 0) || (hcount % 2 != 0) || (bcount % 2 != 0)){ + answer = false; + } else { + answer = true; + } + console.log(answer); + } +} + +module.exports = StringValidator; + +var v = new StringValidator(); +v.validate("([)]") From a208f7228ffc8f4d9c54e529ac6b29e67407c110 Mon Sep 17 00:00:00 2001 From: Daniel Shin Date: Fri, 3 Feb 2017 10:54:14 -0700 Subject: [PATCH 2/2] remove comment --- solution.js | 1 - 1 file changed, 1 deletion(-) diff --git a/solution.js b/solution.js index 76e6522..49df266 100644 --- a/solution.js +++ b/solution.js @@ -24,7 +24,6 @@ class StringValidator{ for(var j = 0 + 1; j < stringArray.length; j++){ var newItem = stringArray[j]; - if(current == "(" && newItem == ")") if(current == "(" && newItem == ")"){ pcount += 1; } if(current == "[" && newItem == "]"){ bcount += 1; } if(current == "{" && newItem == "}"){ hcount += 1; }