Library API
    Preparing search index...

    Function sortInsert

    • Inserts a value into an array at its sorted position using binary search. Supports both primitive values and objects (via a sorting key).

      Type Parameters

      • T
      • K extends string | number | symbol

      Parameters

      • arr: T[] = []

        The array to insert into (defaults to an empty array)

      • val: T

        The value to insert

      • Optionalkey: K

        The property key to sort by if inserting objects

      Returns T[]

      The mutated array containing the inserted value

      sortInsert([1, 3], 2); // [1, 2, 3]