Module

utils/diff

@ckeditor/ckeditor5-utils/src/diff

module

Filtering

Type Definitions

Functions

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

    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.

    Type parameters

    T

    Parameters

    a : ArrayLike<T>

    Input array or string.

    b : ArrayLike<T>

    Output array or string.

    [ cmp ] : ( T, T ) => boolean

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

    Returns

    Array<DiffResult>

    Array of changes.