Skip to content

Commit b904875

Browse files
committed
📦 NEW: Add Parenthesis Checker
Checks weather a parenthesis is balanced or not.
1 parent ee387c3 commit b904875

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

‎Algorithms/parenthesis.js‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
function checkParenthesis(input = "") {
2+
var open = [];
3+
for (var i = 0; i < input.length; i++) {
4+
switch (input[i]) {
5+
case "]":
6+
if ("[" == open[open.length - 1]) {
7+
open.pop();
8+
}
9+
case "}":
10+
if ("{" == open[open.length - 1]) {
11+
open.pop();
12+
}
13+
case ")":
14+
if ("(" == open[open.length - 1]) {
15+
open.pop();
16+
}
17+
break;
18+
default:
19+
open.push(input[i]);
20+
break;
21+
}
22+
}
23+
if (open.length == 0) console.log("Yes");
24+
else console.log("No");
25+
}
26+
27+
checkParenthesis("({}[])");

0 commit comments

Comments
 (0)