12 lines
324 B
Swift
12 lines
324 B
Swift
import Foundation
|
|
|
|
extension Collection {
|
|
|
|
func sorted<T>(ascending: Bool = true, using conversion: (Element) -> T) -> [Element] where T: Comparable {
|
|
guard ascending else {
|
|
return sorted { conversion($0) > conversion($1) }
|
|
}
|
|
return sorted { conversion($0) < conversion($1) }
|
|
}
|
|
}
|