Created
May 15, 2021 21:22
-
-
Save HCLarsen/6b0408713f0ec0b087f6317d001f483f to your computer and use it in GitHub Desktop.
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
class Array(T) | |
# Returns true if the two arrays share no common elements. | |
def disjointed?(other : Array(U)) forall U | |
(self & other).size == 0 | |
end | |
end | |
arr1 = [1 ,2 ,3, 4] | |
arr2 = [3, 4, 5, 6] | |
arr3 = [5, 6, 7, 8] | |
puts arr1.disjointed?(arr2) | |
puts arr2.disjointed?(arr3) | |
puts arr1.disjointed?(arr3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment