Advertisement
Guest User

Untitled

a guest
Jul 20th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 0.57 KB | None | 0 0
  1. struct Account {
  2.     let currencyCode: String
  3.     let openDate: Date
  4. }
  5.  
  6. let currencyCodes = ["RUR": 0, "USD": 1, "EUR": 2]
  7.  
  8. func sortedAccounts(_ accounts: [Account]) -> [Account] {
  9.     return accounts
  10.         .sorted { first, second in
  11.             let secondCurrency = currencyCodes[second.currencyCode] ?? Int.min
  12.             let firstCurrency = currencyCodes[ first.currencyCode] ?? Int.max
  13.             return firstCurrency < secondCurrency
  14.         }
  15.         .sorted { first, second in first.currencyCode == second.currencyCode && first.openDate < second.openDate }
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement