Skip to content

Commit

Permalink
Valid Parentheses
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeltomasik committed Jan 27, 2019
1 parent fceb18d commit e3d81af
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions ValidParentheses.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// https://www.codewars.com/kata/valid-parentheses

// Write a function called that takes a string of parentheses, and determines if the order of the parentheses is valid. The function should return true if the string is valid, and false if it's invalid.

// Examples
// "()" => true
// ")(()))" => false
// "(" => false
// "(())((()())())" => true

function validParentheses(parens){
let str = parens;
while(str.indexOf('()') !== -1){
str = str.replace('()', '');
}

return str.length === 0;
}

0 comments on commit e3d81af

Please sign in to comment.