Skip to content

Instantly share code, notes, and snippets.

@hebertialmeida
Created September 25, 2014 01:28
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/da65f587b44c6aeef76e to your computer and use it in GitHub Desktop.
Save hebertialmeida/da65f587b44c6aeef76e to your computer and use it in GitHub Desktop.
Given 2 arrays of integer (A and B) find the elements from A not belonging to B. Swift implementation.
import UIKit
let a = [1, 2, 3, 4, 5, 6, 7, 50, 30]
let b = [3, 10, 5, 6, 7, 8, 9, 51, 1]
var filter = [Int]()
for number in a {
if !contains(b, number) {
filter.append(number)
}
}
print(filter)
// Returns [2, 4, 50, 30]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment