8000 style: fix basic eslint warnings (#230) · Algorithms-Learn/TypeScript@23ba61b · GitHub
[go: up one dir, main page]

Skip to content

Commit 23ba61b

Browse files
authored
style: fix basic eslint warnings (TheAlgorithms#230)
1 parent 24cbb3b commit 23ba61b

30 files changed

+108
-108
lines changed

backtracking/all_combinations_of_size_k.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
* and repeat the same process for the next number.
1111
*/
1212
export function generateCombinations(n: number, k: number): number[][] {
13-
let combinationsAcc: number[][] = [];
14-
let currentCombination: number[] = [];
13+
const combinationsAcc: number[][] = [];
14+
const currentCombination: number[] = [];
1515

1616
function generateAllCombos(
1717
n: number,

bit_manipulation/add_binary.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
export function addBinary(firstBinaryNo: string, secondBinaryNo: string): string {
99
let lengthOfFirstNumber: number = firstBinaryNo.length - 1;
1010
let lengthOfSecondNumber: number = secondBinaryNo.length - 1;
11-
let solution: string[] = [];
11+
const solution: string[] = [];
1212
let carry: number = 0;
1313

1414
while ( lengthOfFirstNumber >= 0 || lengthOfSecondNumber >= 0) {

data_structures/heap/heap.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export abstract class Heap<T> {
5050
}
5151

5252
public extract(): T {
53-
let maxElement = this.heap[0];
53+
const maxElement = this.heap[0];
5454
this.heap[0] = this.heap[this.size() - 1];
5555
this.heap.pop();
5656
this.sinkDown();
@@ -162,8 +162,8 @@ export class PriorityQueue<T> extends MinHeap<T> {
162162
}
163163

164164
protected swap(a: number, b: number) {
165-
let akey = this.keys_index(this.heap[a]);
166-
let bkey = this.keys_index(this.heap[b]);
165+
const akey = this.keys_index(this.heap[a]);
166+
const bkey = this.keys_index(this.heap[b]);
167167
[this.keys[akey], this.keys[bkey]] = [this.keys[bkey], this.keys[akey]];
168168
super.swap(a, b);
169169
}
@@ -188,7 +188,7 @@ export class PriorityQueue<T> extends MinHeap<T> {
188188
this.insert(value);
189189
return;
190190
}
191-
let key = this.keys[idx];
191+
const key = this.keys[idx];
192192
if (this.compare(this.heap[key], value)) {
193193
// Do not do anything if the value in the heap already has a higher priority.
194194
return;

data_structures/heap/test/heap.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ describe("MaxHeap", () => {
88

99
beforeEach(() => {
1010
heap = new MaxHeap();
11-
for (let element of elements) {
11+
for (const element of elements) {
1212
heap.insert(element);
1313
}
1414
});
@@ -61,7 +61,7 @@ describe("MinHeap", () => {
6161

6262
beforeEach(() => {
6363
heap = new MinHeap();
64-
for (let element of elements) {
64+
for (const element of elements) {
6565
heap.insert(element);
6666
}
6767
});
@@ -106,7 +106,7 @@ describe("MinHeap", () => {
106106
});
107107

108108
it("should increase priority", () => {
109-
let heap = new PriorityQueue((a: number) => { return a; }, elements.length);
109+
const heap = new PriorityQueue((a: number) => { return a; }, elements.length);
110110
elements.forEach((element: number) => {
111111
heap.insert(element);
112112
});

data_structures/queue/linked_queue.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export class LinkedQueue<T> implements Queue<T> {
5555
}
5656

5757
this.size--;
58-
let head = this.head; // We store the head in order not to lose track of it
58+
const head = this.head; // We store the head in order not to lose track of it
5959
this.head = this.head.next; // Update the the head to the next node
6060
return head.value; // Return the value of the head
6161
}

data_structures/stack/test/linked_list_stack.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { LinkedListStack } from "../linked_list_stack";
22

33
describe("Linked List Stack", () => {
4-
let stack: LinkedListStack<number> = new LinkedListStack<number>(4);
4+
const stack: LinkedListStack<number> = new LinkedListStack<number>(4);
55

66
stack.push(1);
77
stack.push(2);

dynamic_programming/knapsack.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export const knapsack = (
2323
const numberOfItems = weights.length;
2424

2525
// Declaring a data structure to store calculated states/values
26-
let dp: number[][] = new Array(numberOfItems + 1);
26+
const dp: number[][] = new Array(numberOfItems + 1);
2727

2828
for (let i = 0; i < dp.length; i++) {
2929
// Placing an array at each index of dp to make it a 2d matrix

graph/bellman_ford.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
export const bellmanFord = (graph: [number, number][][], start: number): number[] | undefined => {
1313
// We save the shortest distance to each node in `distances`. If a node is
1414
// unreachable from the start node, its distance is Infinity.
15-
let distances = Array(graph.length).fill(Infinity);
15+
const distances = Array(graph.length).fill(Infinity);
1616
distances[start] = 0;
1717

1818
// On the i'th iteration, we compute all shortest paths that consists of i+1

graph/dijkstra.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@ import { MinHeap, PriorityQueue } from '../data_structures/heap/heap';
1313
export const dijkstra = (graph: [number, number][][], start: number): number[] => {
1414
// We use a priority queue to make sure we always visit the closest node. The
1515
// queue makes comparisons based on path weights.
16-
let priorityQueue = new PriorityQueue((a: [number, number]) => { return a[0] }, graph.length, (a: [number, number], b: [number, number]) => { return a[1] < b[1] });
16+
const priorityQueue = new PriorityQueue((a: [number, number]) => { return a[0] }, graph.length, (a: [number, number], b: [number, number]) => { return a[1] < b[1] });
1717
priorityQueue.insert([start, 0]);
1818
// We save the shortest distance to each node in `distances`. If a node is
1919
// unreachable from the start node, its distance is Infinity.
20-
let distances = Array(graph.length).fill(Infinity);
20+
const distances = Array(graph.length).fill(Infinity);
2121
distances[start] = 0;
2222

2323
while (priorityQueue.size() > 0) {
2424
const [node, _] = priorityQueue.extract();
2525
graph[node].forEach(([child, weight]) => {
26-
let new_distance = distances[node] + weight;
26+
const new_distance = distances[node] + weight;
2727
if (new_distance < distances[child]) {
2828
// Found a new shortest path to child node. Record its distance and add child to the queue.
2929
// If the child already exists in the queue, the priority will be updated. This will make sure the queue will be at most size V (number of vertices).

graph/floyd_warshall.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
*/
1111
export const floydWarshall = (graph: number[][]): number[][] => {
1212
let distances = structuredClone(graph);
13-
let N = graph.length;
13+
const N = graph.length;
1414

1515
// We begin by setting the weighted adjacency matrix as the shortest paths.
1616
// For the k'th iteration, we try to relax the shortest paths by including node k in the path.
1717
for (let k = 0; k < N; ++k) {
18-
let newDistances = [];
18+
const newDistances = [];
1919
for (let i = 0; i < N; ++i) {
2020
newDistances.push(Array(N).fill(Infinity));
2121
}

0 commit comments

Comments
 (0)
0