如何在多维数组中快速找到项的索引？

`let a = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]`

```public func indicesOf(x: Int, array: [[Int]]) -> (Int, Int) {
...
}```

`indicesOf(7, array: a) // returns (2, 0)`

```for i in 0..<array.count {
for j in 0..<array[i].count {
if array[i][j] == x {
return (i, j)
}
}
}```

```func indicesOf<T: Equatable>(x: T, array: [[T]]) -> (Int, Int)? {
for (i, row) in array.enumerate() {
if let j = row.indexOf(x) {
return (i, j)
}
}
return nil
}```

```extension Array where Element : CollectionType,
Element.Generator.Element : Equatable, Element.Index == Int {
func indicesOf(x: Element.Generator.Element) -> (Int, Int)? {
for (i, row) in self.enumerate() {
if let j = row.indexOf(x) {
return (i, j)
}
}
return nil
}
}

if let (i, j) = a.indicesOf(7) {
print(i, j)
}```

```extension Array where Element : Collection,
Element.Iterator.Element : Equatable, Element.Index == Int {

func indices(of x: Element.Iterator.Element) -> (Int, Int)? {
for (i, row) in self.enumerated() {
if let j = row.index(of: x) {
return (i, j)
}
}
return nil
}
}```