iter-fns - v0.13.0
    Preparing search index...

    Function sorted

    • Sorts an array after copying it, returning the copy.

      This sort is stable, as it calls Array.prototype.sort under the hood which is guaranteed to be stable from ECMAScript 2019 onwards.

      If you are using a comparator that computes a key for each item that is expensive, consider using sortedOn which will compute all the keys up front before sorting.

      Note that this differs from Array.prototype.toSorted in that it will sort numbers correctly by default.

      Type Parameters

      • T

        type of the item

      Parameters

      • xs: readonly T[]

        the array

      • cmp: Compare<T> = compare

        the comparator

      Returns T[]