dist/diff.js
function(seq1, seq2, eq){

    // do compare
    var stepMap = coreCompare(seq1, seq2, eq);

    // transform stepMap
    var contrast = transformStepMap(seq1, seq2, stepMap),
        src = contrast.src,
        target = contrast.target;

    // convert contrast arrays to edit script
    var l = target.length,
        start, len, to,
        notEmpty = function(s){return s !== MARK_EMPTY;},
        script = [],
        i, j;

    for(i = l - 1; i >= 0;){
        // join continuous diffs
        for(j = i; target[j] !== MARK_SAME && j >= 0; j--){}

        if(j < i){
            start = src.slice(0, j + 1).filter(notEmpty).length;            // start pos of diffs (on src)
            len = src.slice(j + 1, i + 1).filter(notEmpty).length;          // length should be replaced (on src)
            to = target.slice(j + 1, i + 1).filter(notEmpty);               // new content

            script.unshift(
                to.length ?
                [start, len, to] :                                          // replace
                [start, len]                                                // remove
            );
        }

        i = j - 1;
    }

    return script;
}
function(seq1, seq2, eq){

    // do compare
    var stepMap = coreCompare(seq1, seq2, eq);

    // transform stepMap
    var contrast = transformStepMap(seq1, seq2, stepMap),
        src = contrast.src,
        target = contrast.target;

    // convert contrast arrays to edit script
    var l = target.length,
        start, len, to,
        notEmpty = function(s){return s !== MARK_EMPTY;},
        script = [],
        i, j;

    for(i = l - 1; i >= 0;){
        // join continuous diffs
        for(j = i; target[j] !== MARK_SAME && j >= 0; j--){}

        if(j < i){
            start = src.slice(0, j + 1).filter(notEmpty).length;            // start pos of diffs (on src)
            len = src.slice(j + 1, i + 1).filter(notEmpty).length;          // length should be replaced (on src)
            to = target.slice(j + 1, i + 1).filter(notEmpty);               // new content

            script.unshift(
                to.length ?
                [start, len, to] :                                          // replace
                [start, len]                                                // remove
            );
        }

        i = j - 1;
    }

    return script;
}
function ( seq1 , seq2 , eq ) { // do compare var stepMap = coreCompare ( seq1 , seq2 , eq ) ; // transform stepMap var contrast = transformStepMap ( seq1 , seq2 , stepMap ) , src = contrast . src , target = contrast . target ; // convert contrast arrays to edit script var l = target . length , start , len , to , notEmpty = function ( s ) { return s !== MARK_EMPTY ; } , script = [ ] , i , j ; for ( i = l - 1 ; i >= 0 ; ) { // join continuous diffs for ( j = i ; target [ j ] !== MARK_SAME && j >= 0 ; j -- ) { } if ( j < i ) { start = src . slice ( 0 , j + 1 ) . filter ( notEmpty ) . length ; // start pos of diffs (on src) len = src . slice ( j + 1 , i + 1 ) . filter ( notEmpty ) . length ; // length should be replaced (on src) to = target . slice ( j + 1 , i + 1 ) . filter ( notEmpty ) ; // new content script . unshift ( to . length ? [ start , len , to ] : // replace [ start , len ] // remove ) ; } i = j - 1 ; } return script ; }
get edit script
get edit script