node-levenshtein
Advanced tools
Comparing version 3.0.0 to 3.0.1
15
index.js
@@ -102,3 +102,3 @@ const peq = new Uint32Array(65535); | ||
module.exports = (a, b) => { | ||
exports.compare = (a, b) => { | ||
if (a.length > b.length) { | ||
@@ -117,1 +117,14 @@ const tmp = b; | ||
exports.compare_many = (str, arr) => { | ||
let min_distance = Infinity | ||
let min_index = 0 | ||
for (let i = 0; i < arr.length; i++) { | ||
const distance = this.compare(str, arr[i]) | ||
if (distance < min_distance) { | ||
min_distance = distance | ||
min_index = i | ||
} | ||
} | ||
return arr[min_index] | ||
} |
{ | ||
"name": "node-levenshtein", | ||
"version": "3.0.0", | ||
"version": "3.0.1", | ||
"description": "Fastest Levenshtein distance implementation in JS.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -17,5 +17,7 @@ # node-levenshtein :rocket: | ||
console.log(levenshtein('lorem', 'ipsum')) | ||
console.log(levenshtein.compare('fast', 'faster')) | ||
//=> 4 | ||
console.log(levenshtein.compare_many('fast', ['slow', 'faster', 'fastest'])) | ||
//=> 'faster' | ||
``` | ||
@@ -22,0 +24,0 @@ |
@@ -67,3 +67,3 @@ const levenshtein = (a, b) => { | ||
while (i < words.length - 1) { | ||
if (nodeLevenshtein(words[i], words[i + 1]) !== levenshtein(words[i], words[i + 1])) { | ||
if (nodeLevenshtein.compare(words[i], words[i + 1]) !== levenshtein(words[i], words[i + 1])) { | ||
errors++; | ||
@@ -87,3 +87,3 @@ } | ||
if (nodeLevenshtein(str1, str2) !== levenshtein(str1, str2)) { | ||
if (nodeLevenshtein.compare(str1, str2) !== levenshtein(str1, str2)) { | ||
errors++; | ||
@@ -103,3 +103,3 @@ console.log('Randomized test:'); | ||
while (k < ps2.length) { | ||
if (nodeLevenshtein(ps1[j].join(''), ps2[k].join('')) !== levenshtein(ps1[j].join(''), ps2[k].join(''))) { | ||
if (nodeLevenshtein.compare(ps1[j].join(''), ps2[k].join('')) !== levenshtein(ps1[j].join(''), ps2[k].join(''))) { | ||
const shrink = `${ps1[j].join('')} ${ps2[k].join('')}`; | ||
@@ -106,0 +106,0 @@ if (shrink.length < shrinked.length) { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
19868
257
43