Skip to content

Instantly share code, notes, and snippets.

@cristhianleonli
Created March 12, 2021 10:21
Show Gist options
  • Save cristhianleonli/5d735c6dbb20d94a166b377e1dbe566c to your computer and use it in GitHub Desktop.
Save cristhianleonli/5d735c6dbb20d94a166b377e1dbe566c to your computer and use it in GitHub Desktop.
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