Avatar
func foo(values: [Int]) throws { if values.isEmpty { return } let shuffled = values.shuffled() guard let first = shuffled.first else { // preconditionFailure("...") try foo() } } do { let array = [2, 3, 5] let a: Int = array[0] let dictionary = ["a": 2, "b": 3, "c": 5] let b: Int? = dictionary["a"] } extension Array where Element: Comparable { mutating func mySort() { for i in indices { for j in indices.dropFirst(i) { // guard let a = self[i], let b = self[j] else { // // ??? // } if self[j] < self[i] { // let t = self[i] // self[i] = self[j] // self[j] = t swapAt(i, j) } } } } } var array = [3, 2, 7, 5] array.mySort() print(array) //extension Array { // func subscript(index: Int) -> Element { // precondition(indices.contains(index), "Index out of range.") // // } //} struct FooError: Error {} func foo() throws -> Never { throw FooError() } print(Array(zip([2, 3, 5, 7], ["a", "b", "c"]))) func myZip<T, U>(_ ts: [T], _ us: [U]) -> [(T, U)] { var result: [(T, U)] = [] for i in ts.indices { guard us.indices.contains(i) else { break } result.append((ts[i], us[i])) } assert(result.count == min(ts.count, us.count)) return result }