-
-
Save xcobar/fcdbcd49a26adcf574c2cf7a2a076852 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
def find(*array) | |
set1 = ["cat", "dog"] | |
set2 = ["apple", "orange"] | |
if (array & set1).size.positive? || (array & set1).size.positive? | |
return 1 | |
elsif (array & set1 & set2).size.positive? | |
return 2 | |
end | |
end | |
find(["cat", "apple"]) #=> 2 | |
find(["cat", "dog"]) #=> 1 | |
find(["apple", "dog"]) #=> 2 | |
find(["orange"]) #=> 1 |
havenwood
commented
May 17, 2019
categories.sum do |category|
next 1 if items.any? { |item| category.include? item }
0
end
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment