Use leven module for levenshtein distance

https://github.com/sindresorhus/leven

No point in bundling code like this.

Leven is also the fastest one: https://github.com/sindresorhus/leven#benchmark
This commit is contained in:
Sindre Sorhus 2015-02-16 22:36:20 +07:00
parent 39c5849604
commit afd07c9172
3 changed files with 2 additions and 39 deletions

View File

@ -1,38 +0,0 @@
// taken from stackoverflow, it's crap i know.
module.exports = function (a, b) {
if (a.length === 0) return b.length;
if (b.length === 0) return a.length;
var matrix = [];
// increment along the first column of each row
var i;
for (i = 0; i <= b.length; i++) {
matrix[i] = [i];
}
// increment each column in the first row
var j;
for (j = 0; j <= a.length; j++) {
matrix[0][j] = j;
}
// Fill in the rest of the matrix
for (i = 1; i <= b.length; i++) {
for (j = 1; j <= a.length; j++) {
if (b.charAt(i - 1) == a.charAt(j - 1)) {
matrix[i][j] = matrix[i - 1][j - 1];
} else {
matrix[i][j] = Math.min(
matrix[i - 1][j - 1] + 1, // substitution
Math.min(
matrix[i][j - 1] + 1, // insertion
matrix[i - 1][j] + 1) // deletion
);
}
}
}
return matrix[b.length][a.length];
};

View File

@ -1,6 +1,6 @@
"use strict";
var levenshtein = require("../../../helpers/levenshtein");
var levenshtein = require("leven");
var messages = require("../../../messages");
var t = require("../../../types");

View File

@ -51,6 +51,7 @@
"fs-readdir-recursive": "0.1.0",
"globals": "^5.1.0",
"js-tokenizer": "1.3.3",
"leven": "^1.0.1",
"lodash": "3.0.0",
"output-file-sync": "1.1.0",
"private": "0.1.6",