Skip to content

Commit 1b0f52d

Browse files
author
Christian Bender
committed
simplified the code and clean up.
1 parent 90aaa3c commit 1b0f52d

File tree

1 file changed

+3
-17
lines changed

1 file changed

+3
-17
lines changed

src/ts/others/balanced-symbols.ts

+3-17
Original file line numberDiff line numberDiff line change
@@ -10,34 +10,20 @@ export function parenthesesChecker(symbols: string) {
1010
let top: string;
1111

1212
while (index < symbols.length && balanced) {
13-
symbol = symbols.charAt(index);
13+
symbol = symbols[index];
1414
if (opens.indexOf(symbol) >= 0) {
1515
stack.push(symbol);
16-
// console.log(`open symbol - stacking ${symbol}`);
1716
} else {
18-
// console.log(`close symbol ${symbol}`);
1917
if (stack.isEmpty()) {
2018
balanced = false;
21-
// console.log('Stack is empty, no more symbols to pop and compare');
2219
} else {
2320
top = stack.pop();
24-
// if (!matches(top, symbol)){
2521
if (!(opens.indexOf(top) === closers.indexOf(symbol))) {
2622
balanced = false;
27-
/* console.log(
28-
`poping symbol ${top} - is not a match compared to ${symbol}`
29-
); */
30-
} /* else {
31-
console.log(
32-
`poping symbol ${top} - is is a match compared to ${symbol}`
33-
);
34-
} */
23+
}
3524
}
3625
}
3726
index++;
3827
}
39-
if (balanced && stack.isEmpty()) {
40-
return true;
41-
}
42-
return false;
28+
return balanced && stack.isEmpty();
4329
}

0 commit comments

Comments
 (0)