Imagine I have the following two arrays:
let array1 = [1,4,6,9,12,18]
let array2 = [6,9,4,18,12,1]
Now I want to find the index of 9
array1.index(of:9) // 3
array2.index(of:9) // 1
Is there anyway to tell the compiler like "Unlike array2, where you need to look up all the indexes one by one, array1 is already sorted, so you can save time and do a binarySearch"
maybe something like:
array1.index(of : 9, isSorted : true)
array2.index(of : 9, isSorted : false)