You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

пре 3 година
1234567891011121314
  1. import leven from 'leven';
  2. export default function levenArray(str, array) {
  3. let minLeven = Number.POSITIVE_INFINITY;
  4. let result = undefined;
  5. for(const item of array) {
  6. const distance = leven(str, item);
  7. if (distance < minLeven) {
  8. minLeven = distance;
  9. result = item;
  10. }
  11. }
  12. return result;
  13. }