Inserts an item into a sorted array, returning a new array.

let data = [ 1, 2, 3, 4 ];
data = insert(data, 2.5);
// [ 1, 2, 2.5, 3, 4 ]

By default uses Javascript comparision semantics. Passing in comparer is needed when working with an array of objects.

  • Type Parameters

    • T

    Parameters

    • sortedArray: T[]

      Sorted array

    • toInsert: T

      Data to insert

    • comparer: Comparer<T> = defaultComparer

      Comparer, uses JS default semantics if not specified.

    Returns T[]