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) -> IntParameters
elementThe element to insert.
isOrderedBeforeA closure which determines whether one element is ordered before another. Should return
truewhenlhsis ordered beforerhs,falsewhenrhsis ordered beforelhsor both share the same position.
View on GitHub