Skip to content

Instantly share code, notes, and snippets.

@hebertialmeida
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hebertialmeida/3a21d3517e5de9a051a7 to your computer and use it in GitHub Desktop.
Save hebertialmeida/3a21d3517e5de9a051a7 to your computer and use it in GitHub Desktop.
Function that merges two lists, but removing duplicate ones. Swift implementation.
import UIKit
var namesA = ["Luis", "Hector", "Selena", "Emmanuel", "Amish", "Rawle", "Selena"]
var namesB = ["Luis", "Selena", "Amish", "Rawle", "George", "Heberti"]
var filter = [String]()
for item in namesA+namesB {
if !contains(filter, item) {
filter.append(item)
}
}
print(filter)
// Returns ["Luis", "Hector", "Selena", "Emmanuel", "Amish", "Rawle", "George", "Heberti"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment