Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 46b2fc7

Browse files
thow error instead of string error message
1 parent 430e7f3 commit 46b2fc7

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

‎src/_DataStructures_/Stack/postfix-expression-evaluation/index.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function evaluatePostfixExpression(expression) {
1313
expression = expression.trim();
1414

1515
if (expression.length === 0 || expression.length === 1) {
16-
returnERROR_STRING;
16+
thrownewError(ERROR_STRING);
1717
}
1818

1919
const s = new Stack();
@@ -52,7 +52,7 @@ function evaluatePostfixExpression(expression) {
5252
if (s.isEmpty()) {
5353
return result;
5454
}
55-
returnERROR_STRING;
55+
thrownewError(ERROR_STRING);
5656
}
5757

5858
module.exports = {

‎src/_DataStructures_/Stack/postfix-expression-evaluation/postfix-expression-evaluation.test.js‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ describe('Postfix expression evaluation', () => {
5656
describe('should throw error on invalid expressions', () => {
5757
const invalidExpressions = ['12', '1', '+', '1+2', '+12'];
5858
test.each(invalidExpressions)('running for %p', (expression) => {
59-
const result = evaluatePostfixExpression(expression);
60-
expect(result).toEqual(ERROR_STRING);
59+
expect(() => evaluatePostfixExpression(expression)).toThrow(ERROR_STRING);
6160
});
6261
});
6362
});

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /