diff --git a/tasks/3. Balanced parentheses/balancedParentheses.js b/tasks/3. Balanced parentheses/balancedParentheses.js index 6944e8c..a2ba218 100644 --- a/tasks/3. Balanced parentheses/balancedParentheses.js +++ b/tasks/3. Balanced parentheses/balancedParentheses.js @@ -1,3 +1,27 @@ export function areParenthesesBalanced(inputString) { // TODO: write your code here -} \ No newline at end of file + let stack = []; + let map = { + '(': ')', + '[': ']', + '{': '}' + } + + for (let i = 0; i < inputString.length; i++) { + + + if (inputString[i] === '(' || inputString[i] === '{' || inputString[i] === '[' ) { + stack.push(inputString[i]); + } + + else { + let last = stack.pop(); + + if (inputString[i] !== map[last]) {return false}; + } + } + + if (stack.length !== 0) {return false}; + + return true; +}