Heres何か私は自分自身を教えようとしています。私は、ネストされたindexArray
の要素のペアがnumberArray
内の要素を指すようにしたい:入れ子にされていない配列のネストされた配列andices Swift
IOW:indexArray
は[[0,2],[3,4]]
を有している場合、私は、ネストされた要素がnumberArray
#0
と
numberArray
で
#2
と素子3,4に向かってポイントします
func findNumIndex(numberArray: [Int], indexArray: [[Int]]) -> Int {
// Use the NESTED index elements to arrive at element index in numberArrray
}
findNumIndex(nums: [0,1,2,3,4,5,6,7,8,9], queries: [[0,1],[1,2],[3,4]])
// We would look at index 0 and 1, index 1 and 2, index 3 and 4 and get the numbers/
最初、私はアレイを平坦化することを考えましたが、それは私が望むものではありません。
Annnnnd私はまだ稼いでいる...笑! –
それには何も問題ありません。私の提案: 'map'、' flatMap'、 'reduce'、' filter'メソッドを読んでください。彼らは本当に多くの状況で便利です! –