Skip to content

Commit 05e3248

Browse files
appgurueugithub-actions
andauthored
chore: format code (TheAlgorithms#1515)
* chore: format code * Updated Documentation in README.md --------- Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
1 parent ce86248 commit 05e3248

File tree

5 files changed

+45
-44
lines changed

5 files changed

+45
-44
lines changed

DIRECTORY.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* [SumOfSubset](Backtracking/SumOfSubset.js)
1010
* **Bit-Manipulation**
1111
* [BinaryCountSetBits](Bit-Manipulation/BinaryCountSetBits.js)
12+
* [GrayCodes](Bit-Manipulation/GrayCodes.js)
1213
* [IsPowerofFour](Bit-Manipulation/IsPowerofFour.js)
1314
* [IsPowerOfTwo](Bit-Manipulation/IsPowerOfTwo.js)
1415
* [LogTwo](Bit-Manipulation/LogTwo.js)
@@ -55,6 +56,7 @@
5556
* [OctToDecimal](Conversions/OctToDecimal.js)
5657
* [OuncesToKilograms](Conversions/OuncesToKilograms.js)
5758
* [RailwayTimeConversion](Conversions/RailwayTimeConversion.js)
59+
* [RgbHslConversion](Conversions/RgbHslConversion.js)
5860
* [RgbHsvConversion](Conversions/RgbHsvConversion.js)
5961
* [RGBToHex](Conversions/RGBToHex.js)
6062
* [RomanToDecimal](Conversions/RomanToDecimal.js)
@@ -72,14 +74,14 @@
7274
* [Graph2](Data-Structures/Graph/Graph2.js)
7375
* [Graph3](Data-Structures/Graph/Graph3.js)
7476
* **Heap**
77+
* [BinaryHeap](Data-Structures/Heap/BinaryHeap.js)
7578
* [KeyPriorityQueue](Data-Structures/Heap/KeyPriorityQueue.js)
76-
* [MaxHeap](Data-Structures/Heap/MaxHeap.js)
77-
* [MinHeap](Data-Structures/Heap/MinHeap.js)
7879
* [MinPriorityQueue](Data-Structures/Heap/MinPriorityQueue.js)
7980
* **Linked-List**
8081
* [AddTwoNumbers](Data-Structures/Linked-List/AddTwoNumbers.js)
8182
* [CycleDetection](Data-Structures/Linked-List/CycleDetection.js)
8283
* [DoublyLinkedList](Data-Structures/Linked-List/DoublyLinkedList.js)
84+
* [MergeTwoSortedLinkedLists](Data-Structures/Linked-List/MergeTwoSortedLinkedLists.js)
8385
* [ReverseSinglyLinkedList](Data-Structures/Linked-List/ReverseSinglyLinkedList.js)
8486
* [SinglyCircularLinkedList](Data-Structures/Linked-List/SinglyCircularLinkedList.js)
8587
* [SinglyLinkedList](Data-Structures/Linked-List/SinglyLinkedList.js)
@@ -88,6 +90,7 @@
8890
* [Queue](Data-Structures/Queue/Queue.js)
8991
* [QueueUsing2Stacks](Data-Structures/Queue/QueueUsing2Stacks.js)
9092
* **Stack**
93+
* [EvaluateExpression](Data-Structures/Stack/EvaluateExpression.js)
9194
* [Stack](Data-Structures/Stack/Stack.js)
9295
* [StackES6](Data-Structures/Stack/StackES6.js)
9396
* **Tree**
@@ -179,6 +182,7 @@
179182
* [DecimalExpansion](Maths/DecimalExpansion.js)
180183
* [DecimalIsolate](Maths/DecimalIsolate.js)
181184
* [DegreeToRadian](Maths/DegreeToRadian.js)
185+
* [Determinant](Maths/Determinant.js)
182186
* [EuclideanDistance](Maths/EuclideanDistance.js)
183187
* [EulerMethod](Maths/EulerMethod.js)
184188
* [EulersTotient](Maths/EulersTotient.js)
@@ -239,6 +243,7 @@
239243
* [RadianToDegree](Maths/RadianToDegree.js)
240244
* [ReverseNumber](Maths/ReverseNumber.js)
241245
* [ReversePolishNotation](Maths/ReversePolishNotation.js)
246+
* [RowEchelon](Maths/RowEchelon.js)
242247
* [ShorsAlgorithm](Maths/ShorsAlgorithm.js)
243248
* [SieveOfEratosthenes](Maths/SieveOfEratosthenes.js)
244249
* [SieveOfEratosthenesIntArray](Maths/SieveOfEratosthenesIntArray.js)

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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 20 additions & 20 deletions
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 }
Lines changed: 14 additions & 15 deletions
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

Lines changed: 3 additions & 6 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy