Skip to content

Commit 46b2fc7

Browse files
committed
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

+2-2
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-
return ERROR_STRING;
16+
throw new Error(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-
return ERROR_STRING;
55+
throw new Error(ERROR_STRING);
5656
}
5757

5858
module.exports = {

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

+1-2
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)