Skip to content

Commit 685785f

Browse files
author
Nejc
committed
refactor: ran prettier on project
1 parent 97808fc commit 685785f

File tree

260 files changed

+1664
-2332
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

260 files changed

+1664
-2332
lines changed

src/algorithms/graph/a-star-search-algorithm/index.test.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,7 @@ describe('AStar', () => {
6565
const getHeuristic: HeuristicCallbackKeys = (i, j) =>
6666
(graph.getVertex(i)?.value || 0) + (graph.getVertex(j)?.value || 0);
6767

68-
expect(aStarGraph(graph, 'A', 'H', getHeuristic)).toEqual([
69-
['A', 'C', 'G', 'H'],
70-
10,
71-
]);
68+
expect(aStarGraph(graph, 'A', 'H', getHeuristic)).toEqual([['A', 'C', 'G', 'H'], 10]);
7269
});
7370

7471
it('should find shortest path between vertices in matrix', () => {

src/algorithms/graph/a-star-search-algorithm/index.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// http://theory.stanford.edu/~amitp/GameProgramming/Heuristics.html
22
import {Graph, Key} from '../../../data-structures/graph';
3-
import createPriorityQueue, {
4-
Item,
5-
} from '../../../data-structures/priority-queue';
3+
import createPriorityQueue, {Item} from '../../../data-structures/priority-queue';
64

75
export type HeuristicCallbackIndexes = (i: number, j: number) => number;
86
export type HeuristicCallbackKeys = (i: Key, j: Key) => number;
@@ -129,8 +127,7 @@ export default function aStar(
129127

130128
// update distances to every connected vertex
131129
const distanceToNext = nextData.distance;
132-
const completeDistance =
133-
currentData.distance + matrix[currentIndex][index];
130+
const completeDistance = currentData.distance + matrix[currentIndex][index];
134131

135132
// if the distance is shorter than update it
136133
if (completeDistance < distanceToNext) {

src/algorithms/graph/articulation-points/index.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ export type VertexMeta = {
55
lowDiscoveryTime: number;
66
};
77

8-
export default function articulationPoints<T>(
9-
graph: Graph<T>,
10-
): Vertex<T>[] | undefined {
8+
export default function articulationPoints<T>(graph: Graph<T>): Vertex<T>[] | undefined {
119
// is empty
1210
if (graph.isEmpty()) return undefined;
1311

@@ -47,10 +45,7 @@ export default function articulationPoints<T>(
4745
const vMeta = visited.get(vertex.key) as VertexMeta;
4846
const nMeta = visited.get(nKey) as VertexMeta;
4947
// update current vertex low discovery time
50-
vMeta.lowDiscoveryTime = Math.min(
51-
vMeta.lowDiscoveryTime,
52-
nMeta.lowDiscoveryTime,
53-
);
48+
vMeta.lowDiscoveryTime = Math.min(vMeta.lowDiscoveryTime, nMeta.lowDiscoveryTime);
5449
visited.set(vertex.key, vMeta);
5550

5651
// vertex is root and has two or more children
@@ -68,10 +63,7 @@ export default function articulationPoints<T>(
6863
const vMeta = visited.get(vertex.key) as VertexMeta;
6964
const nMeta = visited.get(nKey) as VertexMeta;
7065
// update current vertex low discovery time
71-
vMeta.lowDiscoveryTime = Math.min(
72-
vMeta.lowDiscoveryTime,
73-
nMeta.discoveryTime,
74-
);
66+
vMeta.lowDiscoveryTime = Math.min(vMeta.lowDiscoveryTime, nMeta.discoveryTime);
7567
visited.set(vertex.key, vMeta);
7668
}
7769
}

src/algorithms/graph/bridges/index.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,7 @@ export default function bridges<T>(graph: Graph<T>): [Key, Key][] | undefined {
4343
const vMeta = visited.get(vertex.key) as VertexMeta;
4444
const nMeta = visited.get(nKey) as VertexMeta;
4545
// update current vertex low discovery time
46-
vMeta.lowDiscoveryTime = Math.min(
47-
vMeta.lowDiscoveryTime,
48-
nMeta.lowDiscoveryTime,
49-
);
46+
vMeta.lowDiscoveryTime = Math.min(vMeta.lowDiscoveryTime, nMeta.lowDiscoveryTime);
5047
visited.set(vertex.key, vMeta);
5148

5249
// vertex is not root and low discovery time of one of its connected vertices
@@ -60,10 +57,7 @@ export default function bridges<T>(graph: Graph<T>): [Key, Key][] | undefined {
6057
const vMeta = visited.get(vertex.key) as VertexMeta;
6158
const nMeta = visited.get(nKey) as VertexMeta;
6259
// update current vertex low discovery time
63-
vMeta.lowDiscoveryTime = Math.min(
64-
vMeta.lowDiscoveryTime,
65-
nMeta.discoveryTime,
66-
);
60+
vMeta.lowDiscoveryTime = Math.min(vMeta.lowDiscoveryTime, nMeta.discoveryTime);
6761
visited.set(vertex.key, vMeta);
6862
}
6963
}

src/algorithms/graph/depth-first-search/index.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
import {Graph, Key, Vertex} from '../../../data-structures/graph';
22

33
// return data that will be passed to next function call
4-
export type Callback<T> = (
5-
key: Key,
6-
vertex: Vertex<T>,
7-
data?: unknown,
8-
) => unknown | void;
4+
export type Callback<T> = (key: Key, vertex: Vertex<T>, data?: unknown) => unknown | void;
95

106
export interface Options<T> {
117
visitCallback: Callback<T>;

src/algorithms/graph/detect-cycle/undirected.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ import {Graph, Key, Vertex} from '../../../data-structures/graph';
33
export default function detectCycle<T>(graph: Graph<T>): boolean {
44
// is directed
55
if (graph.directed) {
6-
throw new Error(
7-
'Detect cycle algorithms works only for undirected graphs.',
8-
);
6+
throw new Error('Detect cycle algorithms works only for undirected graphs.');
97
}
108
// is empty
119
if (graph.isEmpty()) return false;

src/algorithms/graph/detect-cycle/undirectedDisjointSet.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ import {Graph} from '../../../data-structures/graph';
44
export default function detectCycle<T>(graph: Graph<T>): boolean {
55
// is directed
66
if (graph.directed) {
7-
throw new Error(
8-
'Detect cycle algorithms works only for undirected graphs.',
9-
);
7+
throw new Error('Detect cycle algorithms works only for undirected graphs.');
108
}
119
// is empty
1210
if (graph.isEmpty()) return false;

src/algorithms/graph/dijkstra/index.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import {Edge, Graph, Key} from '../../../data-structures/graph';
2-
import createPriorityQueue, {
3-
Item,
4-
} from '../../../data-structures/priority-queue';
2+
import createPriorityQueue, {Item} from '../../../data-structures/priority-queue';
53

64
export default function dijkstra<T>(
75
graph: Graph<T>,

src/algorithms/graph/floyd-warshall/index.test.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,7 @@ describe('FloydWarshall', () => {
8282

8383
const {vertices, distances} = floydWarshall(graph) || {};
8484

85-
expect(vertices?.map((v) => v.key)).toEqual([
86-
'A',
87-
'B',
88-
'C',
89-
'D',
90-
'E',
91-
'F',
92-
'G',
93-
]);
85+
expect(vertices?.map((v) => v.key)).toEqual(['A', 'B', 'C', 'D', 'E', 'F', 'G']);
9486
expect(distances).toEqual([
9587
[0, 0, 2, Infinity, Infinity, Infinity, Infinity],
9688
[1, 0, 3, Infinity, Infinity, Infinity, Infinity],

src/algorithms/graph/hamiltonian-cycle/index.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ export default function hamiltonianCycle<T>(
66
): Key[][] | undefined {
77
// is directed
88
if (graph.directed) {
9-
throw new Error(
10-
'Hamiltonian cycle algorithms works only for undirected graphs.',
11-
);
9+
throw new Error('Hamiltonian cycle algorithms works only for undirected graphs.');
1210
}
1311
// is empty
1412
if (graph.isEmpty()) return undefined;

0 commit comments

Comments
 (0)