Skip to content

Instantly share code, notes, and snippets.

@krzyzanowskim
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save krzyzanowskim/9a0414aba3daf050d614 to your computer and use it in GitHub Desktop.
Save krzyzanowskim/9a0414aba3daf050d614 to your computer and use it in GitHub Desktop.
Remove array duplicates with reduce()
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