I want to extend Array class so that it can know whether it is sorted (ascending) or not. I want to add a computed property called isSorted. How can I state the
isSorted
Adaptation, a solution that will work in Swift 4
extension Array where Iterator.Element: Comparable { func isSorted(isOrderedBefore: (Iterator.Element, Iterator.Element) -> Bool) -> Bool { for i in 1 ..< self.count { if isOrderedBefore(self[i], self[i-1]) { return false } } return true } }