lib/helper/diff.js
function ld(array1, array2, equalFn){
  var n = array1.length;
  var m = array2.length;
  var equalFn = equalFn || equals;
  var matrix = [];
  for(var i = 0; i <= n; i++){
    matrix.push([i]);
  }
  for(var j=1;j<=m;j++){
    matrix[0][j]=j;
  }
  for(var i = 1; i <= n; i++){
    for(var j = 1; j <= m; j++){
      if(equalFn(array1[i-1], array2[j-1])){
        matrix[i][j] = matrix[i-1][j-1];
      }else{
        matrix[i][j] = Math.min(
          matrix[i-1][j]+1, //delete
          matrix[i][j-1]+1//add
          )
      }
    }
  }
  return matrix;
}
function ld(array1, array2, equalFn){
  var n = array1.length;
  var m = array2.length;
  var equalFn = equalFn || equals;
  var matrix = [];
  for(var i = 0; i <= n; i++){
    matrix.push([i]);
  }
  for(var j=1;j<=m;j++){
    matrix[0][j]=j;
  }
  for(var i = 1; i <= n; i++){
    for(var j = 1; j <= m; j++){
      if(equalFn(array1[i-1], array2[j-1])){
        matrix[i][j] = matrix[i-1][j-1];
      }else{
        matrix[i][j] = Math.min(
          matrix[i-1][j]+1, //delete
          matrix[i][j-1]+1//add
          )
      }
    }
  }
  return matrix;
}
function ld ( array1 , array2 , equalFn ) { var n = array1 . length ; var m = array2 . length ; var equalFn = equalFn || equals ; var matrix = [ ] ; for ( var i = 0 ; i <= n ; i ++ ) { matrix . push ( [ i ] ) ; } for ( var j = 1 ; j <= m ; j ++ ) { matrix [ 0 ] [ j ] = j ; } for ( var i = 1 ; i <= n ; i ++ ) { for ( var j = 1 ; j <= m ; j ++ ) { if ( equalFn ( array1 [ i - 1 ] , array2 [ j - 1 ] ) ) { matrix [ i ] [ j ] = matrix [ i - 1 ] [ j - 1 ] ; } else { matrix [ i ] [ j ] = Math . min ( matrix [ i - 1 ] [ j ] + 1 , //delete matrix [ i ] [ j - 1 ] + 1 //add ) } } } return matrix ; }
array1 - old array array2 - new array
array1 - old array array2 - new array