source: imaps-frontend/node_modules/@babel/helper-validator-option/lib/find-suggestion.js

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 743 bytes
Line 
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.findSuggestion = findSuggestion;
7const {
8 min
9} = Math;
10function levenshtein(a, b) {
11 let t = [],
12 u = [],
13 i,
14 j;
15 const m = a.length,
16 n = b.length;
17 if (!m) {
18 return n;
19 }
20 if (!n) {
21 return m;
22 }
23 for (j = 0; j <= n; j++) {
24 t[j] = j;
25 }
26 for (i = 1; i <= m; i++) {
27 for (u = [i], j = 1; j <= n; j++) {
28 u[j] = a[i - 1] === b[j - 1] ? t[j - 1] : min(t[j - 1], t[j], u[j - 1]) + 1;
29 }
30 t = u;
31 }
32 return u[n];
33}
34function findSuggestion(str, arr) {
35 const distances = arr.map(el => levenshtein(el, str));
36 return arr[distances.indexOf(min(...distances))];
37}
38
39//# sourceMappingURL=find-suggestion.js.map
Note: See TracBrowser for help on using the repository browser.