Function compareArray

  • This sort-comparator function compares two arrays using a provided comparator function. It can compare arrays of any type, as long as the comparator function can handle the type.

    Type Parameters

    • T

      The type of the elements in the arrays.

    Parameters

    • comparator: Comparator = compare

      The comparator function to use for comparing elements.

    Returns Comparator

    A comparator function that can be used for sorting arrays with the Array.prototype.sort method.

    Example

    [[1,2,3], [1,2,2], [1,1,4]].sort(compareArray((a, b) => a - b));;
    //=> [[1,1,4], [1,2,2], [1,2,3]]
    [1, [1,2,3], 6, 2, [0,0], [5,6], [1,[2,[3]]]].sort(compareArray((a, b) => a - b)))
    //=> [[0,0], [1,[2,[3]]], [1,2,3], [5,6], 1, 2, 6]

Generated using TypeDoc