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
If you want simple function without arguments, like sort() or sorted() in Swift:
extension Array where Element : Comparable { func isSorted() -> Bool { guard self.count > 1 else { return true } for i in 1.. self[i] { return false } } return true } }