Skip to content

Commit

Permalink
Merge pull request #36 from giraugh/feat/edit-distance-ops
Browse files Browse the repository at this point in the history
Fix typo in editDistance option name
  • Loading branch information
giraugh authored Jan 12, 2024
2 parents 058591c + 70cbbfb commit 929df1a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/clever-ways-smash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@giraugh/tools": patch
---

Fix typo in editDistance option name
6 changes: 3 additions & 3 deletions lib/strings/editDistance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export type EditDistanceOptions = {
weights: {
insertion?: number,
deletion?: number,
substition?: number,
substitution?: number,
}
}

Expand Down Expand Up @@ -31,7 +31,7 @@ export const editDistance = (source: string, target: string, options?: Partial<E
dynMat[j][i] = Math.min(
dynMat[j][i - 1] + (options?.weights?.deletion ?? 1), // deletion
dynMat[j - 1][i] + (options?.weights?.insertion ?? 1), // insertion
dynMat[j - 1][i - 1] + (options?.weights?.substition ?? 1) * ind, // substitution
dynMat[j - 1][i - 1] + (options?.weights?.substitution ?? 1) * ind, // substitution
)
}
}
Expand Down Expand Up @@ -64,6 +64,6 @@ if (import.meta.vitest) {
it('uses provided operation weights', () => {
expect(editDistance('', 'abc', { weights: { insertion: 2 } })).toBe(6)
expect(editDistance('abc', '', { weights: { deletion: 2 } })).toBe(6)
expect(editDistance('abc', 'defg', { weights: { substition: 2, insertion: 3 } })).toBe(9)
expect(editDistance('abc', 'defg', { weights: { substitution: 2, insertion: 3 } })).toBe(9)
})
}

0 comments on commit 929df1a

Please sign in to comment.