Last active
August 29, 2015 14:06
-
-
Save krzyzanowskim/9a0414aba3daf050d614 to your computer and use it in GitHub Desktop.
Remove array duplicates with reduce()
This file contains hidden or 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
let array = ["P","Q","R","S","T","P","R","A","T","B","C","P","P","P","P","P","C","P","P","J"] | |
let unique = array.reduce([String](), combine: { (array, value) -> [String] in | |
var result = array | |
if (!contains(array, value)) { | |
result.append(value) | |
} | |
return result | |
}) | |
println(unique) // [P, Q, R, S, T, A, B, C, J] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://sketchytech.blogspot.co.uk/2014/08/pure-swift-little-deeper-into-generics.html