MCPcopy Create free account
hub / github.com/arktypeio/arktype / editsBetween

Function editsBetween

ark/aot/util.ts:69–89  ·  view source on GitHub ↗
(a: string, b: string)

Source from the content-addressed store, hash-verified

67}
68
69export const editsBetween = (a: string, b: string): number => {
70 if (Math.abs(a.length - b.length) > 2) return 3
71 let twoBack: number[] = []
72 let last = Array.from({ length: b.length + 1 }, (_, j) => j)
73 for (let i = 1; i <= a.length; i++) {
74 const row = [i]
75 for (let j = 1; j <= b.length; j++) {
76 row[j] = Math.min(
77 last[j] + 1,
78 row[j - 1] + 1,
79 last[j - 1] + (a[i - 1] === b[j - 1] ? 0 : 1),
80 i > 1 && j > 1 && a[i - 1] === b[j - 2] && a[i - 2] === b[j - 1] ?
81 twoBack[j - 2] + 1
82 : 3
83 )
84 }
85 twoBack = last
86 last = row
87 }
88 return Math.min(last[b.length], 3)
89}
90
91export const flatMorph: typeof ArkFlatMorph = ((
92 o: object,

Callers 3

nearestToFunction · 0.90
nearestFunction · 0.90
nearestOptionToFunction · 0.90

Calls 1

fromMethod · 0.65

Tested by

no test coverage detected