Last active
July 10, 2016 09:27
-
-
Save oozoofrog/60947c8e1ce4e76a958cca5e31f36960 to your computer and use it in GitHub Desktop.
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
func -<T: Equatable> (lhs: Array<T>, rhs: Array<T>) -> Array<T> { | |
return lhs.filter({ (lv) -> Bool in | |
return false == rhs.contains(lv) | |
}) | |
} | |
func |<T: Equatable> (lhs: [T], rhs: [T]) -> [T] { | |
return lhs + rhs.filter({ (rv) -> Bool in | |
return false == lhs.contains(rv) | |
}) | |
} | |
func ^<T: Equatable> (lhs: [T], rhs: [T]) -> [T] { | |
return lhs.filter({ false == rhs.contains($0)}) + rhs.filter({ false == lhs.contains($0)}) | |
} | |
prefix func !<T: Equatable> (target: [T]) -> [T] { | |
return target.reversed() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
var a = [1.0, 10.0, 120.0, 32.0, 15.0, 1.0]
var b = [10.0, 11.0, 12.0, 13.0, 1.0]
print("a = (a)")
print("b = (b)")
print("a - b = (a - b)")
print("a | b = (a | b)")
print("a ^ b = (a ^ b)")
print("!a = (!a)")
->
a = [1.0, 10.0, 120.0, 32.0, 15.0, 1.0]
b = [10.0, 11.0, 12.0, 13.0, 1.0]
a - b = [120.0, 32.0, 15.0]
a | b = [1.0, 10.0, 120.0, 32.0, 15.0, 1.0, 11.0, 12.0, 13.0]
a ^ b = [120.0, 32.0, 15.0, 11.0, 12.0, 13.0]
!a = [1.0, 15.0, 32.0, 120.0, 10.0, 1.0]