Advertisement
Guest User

Untitled

a guest
Nov 18th, 2017
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 0.48 KB | None | 0 0
  1. import UIKit
  2.  
  3. extension Array {
  4.     func duplicate(with array: Array) -> Array {
  5.         var result = Array()
  6.         for (key, value) in array.enumerated() {
  7.             result.append(self[key])
  8.             result.append(value)
  9.         }
  10.        
  11.         return result
  12.     }
  13.    
  14.     func duplicateBySelf() -> Array {
  15.         return duplicate(with: self)
  16.     }
  17. }
  18.  
  19. let p = [ [ 1, 0 ], [ 2, 2 ], [3, 4] ]
  20. let q = [ 1, 2, 3, 4 ]
  21.  
  22. p.duplicateBySelf()
  23. q.duplicateBySelf()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement