Iterate through all elements in pair tuples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
public extension Array { | |
// Iterate through all elements in pair tuples | |
// e.g. [1, 2, 3, 4].allPairs = [(1, 2), (2, 3), (3, 4)] | |
var allPairs: [(Element, Element)] { | |
var array: [(Element, Element)] = [] | |
for i in 0..<self.count - 1 { | |
array.append((self[i], self[i+1])) | |
} | |
return array | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment