MCPcopy
hub / github.com/colinhacks/zod / getEditDistance

Function getEditDistance

packages/docs/content/api.test.ts:233–254  ·  view source on GitHub ↗
(left: string, right: string)

Source from the content-addressed store, hash-verified

231}
232
233function getEditDistance(left: string, right: string): number {
234 let previousRow = Array.from({ length: right.length + 1 }, (_, index) => index);
235
236 for (let leftIndex = 0; leftIndex < left.length; leftIndex++) {
237 const currentRow = [leftIndex + 1];
238
239 for (let rightIndex = 0; rightIndex < right.length; rightIndex++) {
240 const substitutionCost = left[leftIndex] === right[rightIndex] ? 0 : 1;
241 currentRow.push(
242 Math.min(
243 currentRow[rightIndex] + 1,
244 previousRow[rightIndex + 1] + 1,
245 previousRow[rightIndex] + substitutionCost
246 )
247 );
248 }
249
250 previousRow = currentRow;
251 }
252
253 return previousRow[right.length] ?? 0;
254}

Callers 1

isLikelyTabValueFunction · 0.85

Calls 1

minMethod · 0.65

Tested by

no test coverage detected