Advertisement
Guest User

Untitled

a guest
Jan 10th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 0.90 KB | None | 0 0
  1.         let dict: [Int: [String: String]] = [1546696330: ["symbol": "ETH", "amount": "1.0"],
  2.                                              1546531017: ["symbol": "ETH", "amount": "1.0"],
  3.                                              1546531031: ["symbol": "XRP", "amount": "200.0"]]
  4.        
  5.         var toKeep: [String: Int] = [:]
  6.         dict.forEach({
  7.             let subDict = $0.value
  8.             if let symbol = subDict["symbol"] {
  9.                 if let currentSaved = toKeep[symbol] {
  10.                     toKeep[symbol] =  currentSaved > $0.key ? $0.key : currentSaved
  11.                 } else {
  12.                     toKeep[symbol] = $0.key
  13.                 }
  14.             }
  15.         })
  16.        
  17.         print("ToKeep: \(toKeep)")
  18.        
  19.         var finalDict: [Int: [String: String]] = [:]
  20.         toKeep.forEach({ finalDict[$0.value] = dict[$0.value] })
  21.         print("finalDict: \(finalDict)")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement