Skip to content

Commit f28628b

Browse files
committed
Format code
1 parent ce86248 commit f28628b

File tree

4 files changed

+38
-42
lines changed

4 files changed

+38
-42
lines changed

Data-Structures/Heap/test/BinaryHeap.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ describe('BinaryHeap', () => {
3636
it('should handle insertion of duplicate values', () => {
3737
// Check if the heap handles duplicate values correctly
3838
minHeap.insert(2)
39-
console.log(minHeap.heap);
39+
console.log(minHeap.heap)
4040
expect(minHeap.heap).toEqual([1, 3, 2, 4, 8, 6, 2])
4141
})
4242

Data-Structures/Stack/EvaluateExpression.js

+20-20
Original file line numberDiff line numberDiff line change
@@ -6,53 +6,53 @@
66
* @returns {number|null} - Result of the expression evaluation, or null if the expression is invalid.
77
*/
88
function evaluatePostfixExpression(expression) {
9-
const stack = [];
9+
const stack = []
1010

1111
// Helper function to perform an operation and push the result to the stack. Returns success.
1212
function performOperation(operator) {
13-
const rightOp = stack.pop(); // Right operand is the top of the stack
14-
const leftOp = stack.pop(); // Left operand is the next item on the stack
13+
const rightOp = stack.pop() // Right operand is the top of the stack
14+
const leftOp = stack.pop() // Left operand is the next item on the stack
1515

1616
if (leftOp === undefined || rightOp === undefined) {
17-
return false; // Invalid expression
17+
return false // Invalid expression
1818
}
1919
switch (operator) {
2020
case '+':
21-
stack.push(leftOp + rightOp);
22-
break;
21+
stack.push(leftOp + rightOp)
22+
break
2323
case '-':
24-
stack.push(leftOp - rightOp);
25-
break;
24+
stack.push(leftOp - rightOp)
25+
break
2626
case '*':
27-
stack.push(leftOp * rightOp);
28-
break;
27+
stack.push(leftOp * rightOp)
28+
break
2929
case '/':
3030
if (rightOp === 0) {
31-
return false;
31+
return false
3232
}
33-
stack.push(leftOp / rightOp);
34-
break;
33+
stack.push(leftOp / rightOp)
34+
break
3535
default:
36-
return false; // Unknown operator
36+
return false // Unknown operator
3737
}
38-
return true;
38+
return true
3939
}
4040

41-
const tokens = expression.split(/\s+/);
41+
const tokens = expression.split(/\s+/)
4242

4343
for (const token of tokens) {
4444
if (!isNaN(parseFloat(token))) {
4545
// If the token is a number, push it to the stack
46-
stack.push(parseFloat(token));
46+
stack.push(parseFloat(token))
4747
} else {
4848
// If the token is an operator, perform the operation
4949
if (!performOperation(token)) {
50-
return null; // Invalid expression
50+
return null // Invalid expression
5151
}
5252
}
5353
}
5454

55-
return (stack.length === 1) ? stack[0] : null;
55+
return stack.length === 1 ? stack[0] : null
5656
}
5757

58-
export { evaluatePostfixExpression };
58+
export { evaluatePostfixExpression }
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
1-
import { evaluatePostfixExpression } from '../EvaluateExpression.js';
1+
import { evaluatePostfixExpression } from '../EvaluateExpression.js'
22

33
describe('evaluatePostfixExpression', () => {
44
it('should evaluate a valid expression', () => {
5-
const expression = '3 4 * 2 / 5 +'; // (3 * 4) / 2 + 5 = 11
6-
const result = evaluatePostfixExpression(expression);
7-
expect(result).toBe(11);
8-
});
5+
const expression = '3 4 * 2 / 5 +' // (3 * 4) / 2 + 5 = 11
6+
const result = evaluatePostfixExpression(expression)
7+
expect(result).toBe(11)
8+
})
99

1010
it('should handle division by zero', () => {
11-
const expression = '3 0 /'; // Division by zero
12-
const result = evaluatePostfixExpression(expression);
13-
expect(result).toBe(null);
14-
});
11+
const expression = '3 0 /' // Division by zero
12+
const result = evaluatePostfixExpression(expression)
13+
expect(result).toBe(null)
14+
})
1515

1616
it('should handle an invalid expression', () => {
17-
const expression = '3 * 4 2 / +'; // Invalid expression
18-
const result = evaluatePostfixExpression(expression);
19-
expect(result).toBe(null);
20-
});
21-
22-
});
17+
const expression = '3 * 4 2 / +' // Invalid expression
18+
const result = evaluatePostfixExpression(expression)
19+
expect(result).toBe(null)
20+
})
21+
})

Maths/test/Determinant.test.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,7 @@ describe('Determinant', () => {
5454
'Square matrix is required.'
5555
],
5656
[[1, 3, 2, [5, 8, 6], 3], 'Input is not a valid 2D matrix.']
57-
])(
58-
'Should return the error message.',
59-
(matrix, expected) => {
60-
expect(() => determinant(matrix)).toThrowError(expected)
61-
}
62-
)
57+
])('Should return the error message.', (matrix, expected) => {
58+
expect(() => determinant(matrix)).toThrowError(expected)
59+
})
6360
})

0 commit comments

Comments
 (0)