Created
March 12, 2021 10:21
-
-
Save cristhianleonli/5d735c6dbb20d94a166b377e1dbe566c to your computer and use it in GitHub Desktop.
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 | |
extension Array { | |
func sorted<T: Comparable>(by compare: (Element) -> T, asc ascendant: Bool = true) -> Array { | |
return self.sorted { | |
if ascendant { | |
return compare($0) < compare($1) | |
} | |
return compare($0) > compare($1) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment