MCPcopy Index your code
hub / github.com/processing/p5.js / computeEditDistance

Function computeEditDistance

src/core/friendly_errors/fes_core.js:264–299  ·  view source on GitHub ↗
(w1, w2)

Source from the content-addressed store, hash-verified

262 * indicates that the words are similar
263 */
264 const computeEditDistance = (w1, w2) => {
265 const l1 = w1.length,
266 l2 = w2.length;
267 if (l1 === 0) return w2;
268 if (l2 === 0) return w1;
269
270 let prev = [];
271 let cur = [];
272
273 for (let j = 0; j < l2 + 1; j++) {
274 cur[j] = j;
275 }
276
277 prev = cur;
278
279 for (let i = 1; i < l1 + 1; i++) {
280 cur = [];
281 for (let j = 0; j < l2 + 1; j++) {
282 if (j === 0) {
283 cur[j] = i;
284 } else {
285 let a1 = w1[i - 1],
286 a2 = w2[j - 1];
287 let temp = 999999;
288 let cost = a1.toLowerCase() === a2.toLowerCase() ? 0 : 1;
289 temp = temp > cost + prev[j - 1] ? cost + prev[j - 1] : temp;
290 temp = temp > 1 + cur[j - 1] ? 1 + cur[j - 1] : temp;
291 temp = temp > 1 + prev[j] ? 1 + prev[j] : temp;
292 cur[j] = temp;
293 }
294 }
295 prev = cur;
296 }
297
298 return cur[l2];
299 };
300
301 /**
302 * Whether or not p5.js is running in an environment where `preload` will be

Callers 1

handleMisspellingFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected