Skip to content

Instantly share code, notes, and snippets.

@HCLarsen
Created May 15, 2021 21:22
Show Gist options
  • Save HCLarsen/6b0408713f0ec0b087f6317d001f483f to your computer and use it in GitHub Desktop.
Save HCLarsen/6b0408713f0ec0b087f6317d001f483f to your computer and use it in GitHub Desktop.
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