File tree Expand file tree Collapse file tree 1 file changed +8
-6
lines changed Expand file tree Collapse file tree 1 file changed +8
-6
lines changed Original file line number Diff line number Diff line change @@ -11,21 +11,23 @@ export function parenthesesChecker(symbols) {
1111 let top ;
1212
1313 while ( index < symbols . length && balanced ) {
14- symbol = symbols . charAt ( index ) ;
14+ symbol = symbols [ index ] ;
1515 if ( opens . indexOf ( symbol ) >= 0 ) {
1616 stack . push ( symbol ) ;
1717 } else if ( stack . isEmpty ( ) ) {
1818 balanced = false ;
1919 } else {
20- top = stack . pop ( ) ;
20+ // makes sure the stack isn't empty.
21+ if ( ! stack . isEmpty ( ) ) {
22+ top = stack . pop ( ) ;
23+ } else { // error case
24+ balanced = false ;
25+ }
2126 if ( ! ( opens . indexOf ( top ) === closers . indexOf ( symbol ) ) ) {
2227 balanced = false ;
2328 }
2429 }
2530 index ++ ;
2631 }
27- if ( balanced && stack . isEmpty ( ) ) {
28- return true ;
29- }
30- return false ;
32+ return balanced && stack . isEmpty ( ) ;
3133}
You can’t perform that action at this time.
0 commit comments