Skip to content

Commit

Permalink
style: use for-of (#241)
Browse files Browse the repository at this point in the history
  • Loading branch information
vil02 authored Jun 6, 2024
1 parent a08a122 commit 8c8a0ec
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
10 changes: 5 additions & 5 deletions dynamic_programming/coin_change.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ export const coinChange = (money: number, coins: number[]): CoinChange => {
minCoins[0] = 0

// Fill in the DP table
for (let i = 0; i < coins.length; i++) {
for (const coin of coins) {
for (let j = 0; j <= money; j++) {
if (j >= coins[i]) {
if (minCoins[j] > 1 + minCoins[j - coins[i]]) {
minCoins[j] = 1 + minCoins[j - coins[i]]
lastCoin[j] = coins[i]
if (j >= coin) {
if (minCoins[j] > 1 + minCoins[j - coin]) {
minCoins[j] = 1 + minCoins[j - coin]
lastCoin[j] = coin
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions graph/prim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ const add_children = (
priorityQueue: PriorityQueue<Edge>,
node: number
) => {
for (let i = 0; i < graph[node].length; ++i) {
const out_edge = graph[node][i]
for (const out_edge of graph[node]) {
// 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.
priorityQueue.increasePriority(
out_edge[0],
Expand Down
2 changes: 1 addition & 1 deletion sorts/counting_sort.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const countingSort = (inputArr: number[], min: number, max: number) => {

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

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

count[0] -= 1

Expand Down

0 comments on commit 8c8a0ec

Please sign in to comment.