Created
May 2, 2016 21:04
-
-
Save JoeFerrucci/82c33b23f59526089038fe99d2f0bdba to your computer and use it in GitHub Desktop.
Threw this together real quick. I'll refactor for more performant code and structure. Performance profiling coming soon.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
extension Array { | |
func zipmap(key key: String, value: String, container: [AnyObject]) -> [[String:AnyObject]] { | |
var result = [[String:AnyObject]]() | |
let count = min(self.count, container.count) | |
for i in 0..<count { | |
var mapping = [String:AnyObject]() | |
let k = self[i] as! String | |
let v = container[i] | |
mapping[key] = k | |
mapping[value] = v | |
result.append(mapping) | |
} | |
return result | |
} | |
} | |
let students = ["Joe", "Charlie", "Benjamin", "Peyton", "Alicia"] | |
let grades = [91, 82, 97, 99, 100] | |
let map = students.zipmap(key: "name", value: "grade", container: grades) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment