index.mjs 321 B

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. }