examples/vendor/knockback-core-stack-0.16.7.js
function calculateEditDistanceMatrix(oldArray, newArray, maxAllowedDistance) {
        var distances = [];
        for (var i = 0; i <= newArray.length; i++)
            distances[i] = [];

        // Top row - transform old array into empty array via deletions
        for (var i = 0, j = Math.min(oldArray.length, maxAllowedDistance); i <= j; i++)
            distances[0][i] = i;

        // Left row - transform empty array into new array via additions
        for (var i = 1, j = Math.min(newArray.length, maxAllowedDistance); i <= j; i++) {
            distances[i][0] = i;
        }

        // Fill out the body of the array
        var oldIndex, oldIndexMax = oldArray.length, newIndex, newIndexMax = newArray.length;
        var distanceViaAddition, distanceViaDeletion;
        for (oldIndex = 1; oldIndex <= oldIndexMax; oldIndex++) {
            var newIndexMinForRow = Math.max(1, oldIndex - maxAllowedDistance);
            var newIndexMaxForRow = Math.min(newIndexMax, oldIndex + maxAllowedDistance);
            for (newIndex = newIndexMinForRow; newIndex <= newIndexMaxForRow; newIndex++) {
                if (oldArray[oldIndex - 1] === newArray[newIndex - 1])
                    distances[newIndex][oldIndex] = distances[newIndex - 1][oldIndex - 1];
                else {
                    var northDistance = distances[newIndex - 1][oldIndex] === undefined ? Number.MAX_VALUE : distances[newIndex - 1][oldIndex] + 1;
                    var westDistance = distances[newIndex][oldIndex - 1] === undefined ? Number.MAX_VALUE : distances[newIndex][oldIndex - 1] + 1;
                    distances[newIndex][oldIndex] = Math.min(northDistance, westDistance);
                }
            }
        }

        return distances;
    }
function calculateEditDistanceMatrix(oldArray, newArray, maxAllowedDistance) {
        var distances = [];
        for (var i = 0; i <= newArray.length; i++)
            distances[i] = [];

        // Top row - transform old array into empty array via deletions
        for (var i = 0, j = Math.min(oldArray.length, maxAllowedDistance); i <= j; i++)
            distances[0][i] = i;

        // Left row - transform empty array into new array via additions
        for (var i = 1, j = Math.min(newArray.length, maxAllowedDistance); i <= j; i++) {
            distances[i][0] = i;
        }

        // Fill out the body of the array
        var oldIndex, oldIndexMax = oldArray.length, newIndex, newIndexMax = newArray.length;
        var distanceViaAddition, distanceViaDeletion;
        for (oldIndex = 1; oldIndex <= oldIndexMax; oldIndex++) {
            var newIndexMinForRow = Math.max(1, oldIndex - maxAllowedDistance);
            var newIndexMaxForRow = Math.min(newIndexMax, oldIndex + maxAllowedDistance);
            for (newIndex = newIndexMinForRow; newIndex <= newIndexMaxForRow; newIndex++) {
                if (oldArray[oldIndex - 1] === newArray[newIndex - 1])
                    distances[newIndex][oldIndex] = distances[newIndex - 1][oldIndex - 1];
                else {
                    var northDistance = distances[newIndex - 1][oldIndex] === undefined ? Number.MAX_VALUE : distances[newIndex - 1][oldIndex] + 1;
                    var westDistance = distances[newIndex][oldIndex - 1] === undefined ? Number.MAX_VALUE : distances[newIndex][oldIndex - 1] + 1;
                    distances[newIndex][oldIndex] = Math.min(northDistance, westDistance);
                }
            }
        }

        return distances;
    }
function calculateEditDistanceMatrix ( oldArray , newArray , maxAllowedDistance ) { var distances = [ ] ; for ( var i = 0 ; i <= newArray . length ; i ++ ) distances [ i ] = [ ] ; // Top row - transform old array into empty array via deletions for ( var i = 0 , j = Math . min ( oldArray . length , maxAllowedDistance ) ; i <= j ; i ++ ) distances [ 0 ] [ i ] = i ; // Left row - transform empty array into new array via additions for ( var i = 1 , j = Math . min ( newArray . length , maxAllowedDistance ) ; i <= j ; i ++ ) { distances [ i ] [ 0 ] = i ; } // Fill out the body of the array var oldIndex , oldIndexMax = oldArray . length , newIndex , newIndexMax = newArray . length ; var distanceViaAddition , distanceViaDeletion ; for ( oldIndex = 1 ; oldIndex <= oldIndexMax ; oldIndex ++ ) { var newIndexMinForRow = Math . max ( 1 , oldIndex - maxAllowedDistance ) ; var newIndexMaxForRow = Math . min ( newIndexMax , oldIndex + maxAllowedDistance ) ; for ( newIndex = newIndexMinForRow ; newIndex <= newIndexMaxForRow ; newIndex ++ ) { if ( oldArray [ oldIndex - 1 ] === newArray [ newIndex - 1 ] ) distances [ newIndex ] [ oldIndex ] = distances [ newIndex - 1 ] [ oldIndex - 1 ] ; else { var northDistance = distances [ newIndex - 1 ] [ oldIndex ] === undefined ? Number . MAX_VALUE : distances [ newIndex - 1 ] [ oldIndex ] + 1 ; var westDistance = distances [ newIndex ] [ oldIndex - 1 ] === undefined ? Number . MAX_VALUE : distances [ newIndex ] [ oldIndex - 1 ] + 1 ; distances [ newIndex ] [ oldIndex ] = Math . min ( northDistance , westDistance ) ; } } } return distances ; }
Simple calculation based on Levenshtein distance.
Simple calculation based on Levenshtein distance .