diff --git a/semana22/checaParenteses/index.js b/semana22/checaParenteses/index.js new file mode 100644 index 0000000..1363ead --- /dev/null +++ b/semana22/checaParenteses/index.js @@ -0,0 +1,26 @@ +function checaParenteses(str) { + const stack = []; + + for (let char of str) { + if (char === "(" || char === "[" || char === "{") { + stack.push(char); + } else { + const lastOpeningChar = stack.pop(); + if(!lastOpeningChar) { + return false + } else if ( + (lastOpeningChar === "(" && char !== ")") || + (lastOpeningChar === "[" && char !== "]") || + (lastOpeningChar === "{" && char !== "}") + ) { + return false; + } + } + } + + if (stack.length > 0) { + return false; + } + + return true; +} \ No newline at end of file