Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simplified the code and clean up. #55

Merged
merged 1 commit into from
Apr 25, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
simplified the code and clean up.
  • Loading branch information
Christian Bender committed Apr 9, 2018
commit 1b0f52d9adbca6cdae85fc821533e0bcea25fee1
20 changes: 3 additions & 17 deletions src/ts/others/balanced-symbols.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,20 @@ export function parenthesesChecker(symbols: string) {
let top: string;

while (index < symbols.length && balanced) {
symbol = symbols.charAt(index);
symbol = symbols[index];
if (opens.indexOf(symbol) >= 0) {
stack.push(symbol);
// console.log(`open symbol - stacking ${symbol}`);
} else {
// console.log(`close symbol ${symbol}`);
if (stack.isEmpty()) {
balanced = false;
// console.log('Stack is empty, no more symbols to pop and compare');
} else {
top = stack.pop();
// if (!matches(top, symbol)){
if (!(opens.indexOf(top) === closers.indexOf(symbol))) {
balanced = false;
/* console.log(
`poping symbol ${top} - is not a match compared to ${symbol}`
); */
} /* else {
console.log(
`poping symbol ${top} - is is a match compared to ${symbol}`
);
} */
}
}
}
index++;
}
if (balanced && stack.isEmpty()) {
return true;
}
return false;
return balanced && stack.isEmpty();
}