Inserts a value into an array at its sorted position using binary search. Supports both primitive values and objects (via a sorting key).
The array to insert into (defaults to an empty array)
The value to insert
Optional
The property key to sort by if inserting objects
The mutated array containing the inserted value
sortInsert([1, 3], 2); // [1, 2, 3] Copy
sortInsert([1, 3], 2); // [1, 2, 3]
Inserts a value into an array at its sorted position using binary search. Supports both primitive values and objects (via a sorting key).