Guest User

Untitled

a guest
May 25th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.40 KB | None | 0 0
  1. extension Array {
  2. func sortedBy<T: Comparable>(_ cb: (Element) -> T) -> [Element] {
  3. return self.sorted(by: { (l: Element, r: Element) -> Bool in
  4. return cb(l) < cb(r)
  5. })
  6. }
  7.  
  8. func sortedByDescending<T: Comparable>(_ cb: (Element) -> T) -> [Element] {
  9. return self.sorted(by: { (l: Element, r: Element) -> Bool in
  10. return cb(l) > cb(r)
  11. })
  12. }
  13. }
Add Comment
Please, Sign In to add comment