Array
public extension Array
-
Finds the index where an element should be in a sorted array.
Can be used to determine the insertion index into the sorted array. Requires the array being in sorted order. Finding the index has a complexity of O(log n). Uses “binary search” for determining the matching index: https://en.wikipedia.org/wiki/Binary_search_algorithm
Declaration
Swift
func orderedIndexOf(_ element: Element, isOrderedBefore: (_ lhs: Element, _ rhs: Element) -> Bool) -> Int
Parameters
element
The element to insert.
isOrderedBefore
A closure which determines whether one element is ordered before another. Should return
true
whenlhs
is ordered beforerhs
,false
whenrhs
is ordered beforelhs
or both share the same position.