common-stuff
    Preparing search index...

    Function sortByCb

    • Creates sort callback which can be used for array.sort input. A custom key function can be supplied to customize the sort order. Key can return any nested data structure, supports number, booleans, arrays.

      Type Parameters

      • T

      Parameters

      • key: (item: T) => unknown = ...

        a function to execute to decide the order

      Returns (a: T, b: T) => number

      array.sort compatible callback

      // Sort by object key
      arr.sort(sortByCb(v => v.myKey))
      // Sort by number in reversed order
      arr.sort(sortByCb(v => v.numberKey * -1))
      // Sort by object key, then by boolean value in revered order
      arr.sort(sortByCb(v => [v.myKey, !v.boolValue])