Skip to content

Commit 8c8a0ec

Browse files
authored
style: use for-of (#241)
1 parent a08a122 commit 8c8a0ec

File tree

3 files changed

+7
-8
lines changed

3 files changed

+7
-8
lines changed

dynamic_programming/coin_change.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ export const coinChange = (money: number, coins: number[]): CoinChange => {
1717
minCoins[0] = 0
1818

1919
// Fill in the DP table
20-
for (let i = 0; i < coins.length; i++) {
20+
for (const coin of coins) {
2121
for (let j = 0; j <= money; j++) {
22-
if (j >= coins[i]) {
23-
if (minCoins[j] > 1 + minCoins[j - coins[i]]) {
24-
minCoins[j] = 1 + minCoins[j - coins[i]]
25-
lastCoin[j] = coins[i]
22+
if (j >= coin) {
23+
if (minCoins[j] > 1 + minCoins[j - coin]) {
24+
minCoins[j] = 1 + minCoins[j - coin]
25+
lastCoin[j] = coin
2626
}
2727
}
2828
}

graph/prim.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ const add_children = (
5151
priorityQueue: PriorityQueue<Edge>,
5252
node: number
5353
) => {
54-
for (let i = 0; i < graph[node].length; ++i) {
55-
const out_edge = graph[node][i]
54+
for (const out_edge of graph[node]) {
5655
// By increasing the priority, we ensure we only add each vertex to the queue one time, and the queue will be at most size V.
5756
priorityQueue.increasePriority(
5857
out_edge[0],

sorts/counting_sort.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export const countingSort = (inputArr: number[], min: number, max: number) => {
1313

1414
const count = new Array(max - min + 1).fill(0)
1515

16-
for (let i = 0; i < inputArr.length; i++) count[inputArr[i] - min]++
16+
for (const element of inputArr) count[element - min]++
1717

1818
count[0] -= 1
1919

0 commit comments

Comments
 (0)