func insert(tracks: [Track], track: Track, isGreater: (a: Track, b: Track) -> Bool?) -> Int { var high: Int = tracks.count - 1 var low: Int = 0 var index: Int while (true) { index = (high - low) / 2 if (high - low) < 2 { return index } print(index) let result = isGreater(a: track, b: tracks[index]) if result == true { low = index + 1 } else if result == false { high = index - 1 } else { return index } } }