dist/fuzzy-match-utils.js
function fullStringDistance(a, b) {
    var aLength = a.length;
    var bLength = b.length;
    var table = [];

    if (!aLength) {
        return bLength;
    }
    if (!bLength) {
        return aLength;
    }

    // Initialize the table axes:
    //
    //    0 1 2 3 4 ... bLength
    //    1
    //    2
    //
    //   ...
    //
    // aLength
    //
    for (var x = 0; x <= aLength; ++x) {
        table[x] = [x];
    }
    for (var y = 0; y <= bLength; ++y) {
        table[0][y] = y;
    }

    // Populate the rest of the table with a dynamic programming algorithm.
    for (var _x2 = 1; _x2 <= aLength; ++_x2) {
        for (var _y2 = 1; _y2 <= bLength; ++_y2) {
            table[_x2][_y2] = a[_x2 - 1] === b[_y2 - 1] ? table[_x2 - 1][_y2 - 1] : 1 + Math.min(table[_x2 - 1][_y2], // Substitution,
            table[_x2][_y2 - 1], // insertion,
            table[_x2 - 1][_y2 - 1]); // and deletion.
        }
    }

    return table[aLength][bLength];
}
function fullStringDistance(a, b) {
    var aLength = a.length;
    var bLength = b.length;
    var table = [];

    if (!aLength) {
        return bLength;
    }
    if (!bLength) {
        return aLength;
    }

    // Initialize the table axes:
    //
    //    0 1 2 3 4 ... bLength
    //    1
    //    2
    //
    //   ...
    //
    // aLength
    //
    for (var x = 0; x <= aLength; ++x) {
        table[x] = [x];
    }
    for (var y = 0; y <= bLength; ++y) {
        table[0][y] = y;
    }

    // Populate the rest of the table with a dynamic programming algorithm.
    for (var _x2 = 1; _x2 <= aLength; ++_x2) {
        for (var _y2 = 1; _y2 <= bLength; ++_y2) {
            table[_x2][_y2] = a[_x2 - 1] === b[_y2 - 1] ? table[_x2 - 1][_y2 - 1] : 1 + Math.min(table[_x2 - 1][_y2], // Substitution,
            table[_x2][_y2 - 1], // insertion,
            table[_x2 - 1][_y2 - 1]); // and deletion.
        }
    }

    return table[aLength][bLength];
}
function fullStringDistance ( a , b ) { var aLength = a . length ; var bLength = b . length ; var table = [ ] ; if ( ! aLength ) { return bLength ; } if ( ! bLength ) { return aLength ; } // Initialize the table axes: // //    0 1 2 3 4 ... bLength //    1 //    2 // //   ... // // aLength // for ( var x = 0 ; x <= aLength ; ++ x ) { table [ x ] = [ x ] ; } for ( var y = 0 ; y <= bLength ; ++ y ) { table [ 0 ] [ y ] = y ; } // Populate the rest of the table with a dynamic programming algorithm. for ( var _x2 = 1 ; _x2 <= aLength ; ++ _x2 ) { for ( var _y2 = 1 ; _y2 <= bLength ; ++ _y2 ) { table [ _x2 ] [ _y2 ] = a [ _x2 - 1 ] === b [ _y2 - 1 ] ? table [ _x2 - 1 ] [ _y2 - 1 ] : 1 + Math . min ( table [ _x2 - 1 ] [ _y2 ] , // Substitution, table [ _x2 ] [ _y2 - 1 ] , // insertion, table [ _x2 - 1 ] [ _y2 - 1 ] ) ; // and deletion. } } return table [ aLength ] [ bLength ] ; }
Returns the Levenshtein distance between two strings.

NOTE: The Jaro-Winkler distance also worked well and is slightly more
performant. Levenshtein seems to match more reliably, which is more
important here.

@param  a  The first string for comparison.
@param  b  The second string for comparison.

@return The Levenshtein distance, where lower distance indicates higher
similarity.
Returns the Levenshtein distance between two strings .