Report an issue
Module

utils/diff

@ckeditor/ckeditor5-utils/src/diff

module

Filtering

Functions

  • diff( a, b, [ cmp ] ) → Array

    static

    Calculates the difference between two arrays or strings producing an array containing a list of changes necessary to transform input into output.

    diff( 'aba', 'acca' ); // [ 'equal', 'insert', 'insert', 'delete', 'equal' ]

    This function is based on the "O(NP) Sequence Comparison Algorithm" by Sun Wu, Udi Manber, Gene Myers, Webb Miller. Unfortunately, while it gives the most precise results, its to complex for longer strings/arrow (above 200 items). Therefore, diff() automatically switches to fastDiff() when detecting such a scenario. The return formats of both functions are identical.

    Parameters

    a : Array | String

    Input array or string.

    b : Array | String

    Output array or string.

    [ cmp ] : function

    Optional function used to compare array values, by default === is used.

    Returns

    Array

    Array of changes.