We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 90aaa3c commit 7309191Copy full SHA for 7309191
src/js/others/balanced-symbols.js
@@ -11,21 +11,23 @@ export function parenthesesChecker(symbols) {
11
let top;
12
13
while (index < symbols.length && balanced) {
14
- symbol = symbols.charAt(index);
+ symbol = symbols[index];
15
if (opens.indexOf(symbol) >= 0) {
16
stack.push(symbol);
17
} else if (stack.isEmpty()) {
18
balanced = false;
19
} else {
20
- top = stack.pop();
+ // makes sure the stack isn't empty.
21
+ if (!stack.isEmpty()) {
22
+ top = stack.pop();
23
+ } else { // error case
24
+ balanced = false;
25
+ }
26
if (!(opens.indexOf(top) === closers.indexOf(symbol))) {
27
28
}
29
30
index++;
31
- if (balanced && stack.isEmpty()) {
- return true;
- }
- return false;
32
+ return balanced && stack.isEmpty();
33
0 commit comments