index.js 605 B

123456789101112131415161718192021222324252627
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = levenArray;
  6. var _leven = _interopRequireDefault(require("leven"));
  7. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  8. function levenArray(str, array) {
  9. var minLeven = Number.POSITIVE_INFINITY;
  10. var result = undefined;
  11. for (var _i2 = 0; _i2 < array.length; _i2++) {
  12. var item = array[_i2];
  13. var distance = (0, _leven.default)(str, item);
  14. if (distance < minLeven) {
  15. minLeven = distance;
  16. result = item;
  17. }
  18. }
  19. return result;
  20. }