mirror of
https://github.com/TheAlgorithms/Ruby
synced 2024-12-26 21:58:56 +01:00
Minor changes
This commit is contained in:
parent
d6e7b9f1d8
commit
745b66227b
1 changed files with 10 additions and 9 deletions
|
@ -32,24 +32,25 @@ def arrays_intersection(arr1, arr2, arr3)
|
|||
add_to_hash(arr2, hash)
|
||||
add_to_hash(arr3, hash)
|
||||
|
||||
hash.select { |key, value| value == 3 }.keys
|
||||
hash.select { |_key, value| value == 3 }.keys
|
||||
end
|
||||
|
||||
def add_to_hash(arr, hash)
|
||||
arr.each_with_index do |value, index|
|
||||
hash[value] += 1
|
||||
arr.count.times do |pointer|
|
||||
value = arr[pointer]
|
||||
hash[value] += 1
|
||||
end
|
||||
end
|
||||
|
||||
arr1 = [1,2,3,4,5]
|
||||
arr2 = [1,2,5,7,9]
|
||||
arr3 = [1,3,4,5,8]
|
||||
arr1 = [1, 2, 3, 4, 5]
|
||||
arr2 = [1, 2, 5, 7, 9]
|
||||
arr3 = [1, 3, 4, 5, 8]
|
||||
print arrays_intersection(arr1, arr2, arr3)
|
||||
# Output: [1,5]
|
||||
# Explanation: Only 1 and 5 appeared in the three arrays.
|
||||
|
||||
arr1 = [197,418,523,876,1356]
|
||||
arr2 = [501,880,1593,1710,1870]
|
||||
arr3 = [521,682,1337,1395,1764]
|
||||
arr1 = [197, 418, 523, 876, 1356]
|
||||
arr2 = [501, 880, 1593, 1710, 1870]
|
||||
arr3 = [521, 682, 1337, 1395, 1764]
|
||||
print arrays_intersection(arr1, arr2, arr3)
|
||||
# Output: []
|
||||
|
|
Loading…
Reference in a new issue