{"size": 2637, "ext": "js", "max_stars_repo_path": "node_modules/universal-diff/lib/script.js", "max_stars_repo_name": "lipenghuihenu/hexo", "max_stars_repo_stars_event_min_datetime": "2015-01-29T13:41:31.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-20T06:31:33.000Z", "max_issues_repo_path": "node_modules/universal-diff/lib/script.js", "max_issues_repo_name": "lipenghuihenu/hexo", "max_issues_repo_issues_event_min_datetime": "2015-02-06T02:19:28.000Z", "max_issues_repo_issues_event_max_datetime": "2017-04-14T06:48:47.000Z", "max_forks_repo_path": "node_modules/universal-diff/lib/script.js", "max_forks_repo_name": "lipenghuihenu/hexo", "max_forks_repo_forks_event_min_datetime": "2015-02-06T01:44:29.000Z", "max_forks_repo_forks_event_max_datetime": "2020-06-04T01:38:57.000Z"}
{"max_stars_count": 46, "max_issues_count": 2, "max_forks_count": 11, "avg_line_length": 24.8773584906, "max_line_length": 113, "alphanum_fraction": 0.4539249147}
/*
 * stepMap to edit-script
 */

// stepMap to contrast array
var transformStepMap = function(seq1, seq2, stepMap){
    // get contrast arrays (src & target) by analyze step by step
    var l1 = seq1.length,
        l2 = seq2.length,
        src = [], target = [];

    for(var i = l1,j = l2; i > 0 || j > 0;){
        switch(stepMap[i][j]){

        case STEP_NOCHANGE:
            src.unshift(seq1[i-1]);
            target.unshift(MARK_SAME);
            i -= 1;
            j -= 1;
            break;

        case STEP_REPLACE:
            src.unshift(seq1[i-1]);
            target.unshift(seq2[j-1]);
            i -= 1;
            j -= 1;
            break;

        case STEP_REMOVE:
            src.unshift(seq1[i-1]);
            target.unshift(MARK_EMPTY);
            i -= 1;
            j -= 0;
            break;

        case STEP_INSERT:
            src.unshift(MARK_EMPTY);
            target.unshift(seq2[j-1]);
            i -= 0;
            j -= 1;
            break;

        }
    }

    return {
        src: src,
        target: target
    };
};

// get edit script
var compare = 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;
};

// merge
var merge = function(seq, script){
    var result = seq.slice();

    for(var i = script.length - 1, modify; i >= 0; i--){
        modify = script[i];
        var to = modify[2];
        if(to){
            modify = modify.slice(0, 2).concat(to);
        }
        result.splice.apply(result, modify);
    }

    return result;
};