forked from Luce-MG/backend-developer-tests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelper.rb
18 lines (15 loc) · 819 Bytes
/
helper.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
def compare_hashes(hash1, hash2)
# Find the maximum width of each column
key_width = (hash1.keys + hash2.keys).map(&:length).max
value_width = (hash1.values + hash2.values).map { |v| v.to_s.length }.max
# Print the table header
puts "+#{'-' * (key_width + 2)}+#{'-' * (value_width + 2)}+#{'-' * (value_width + 2)}+"
puts "| #{'Key'.ljust(key_width)} | #{'You'.ljust(value_width)} | #{'Rand'.ljust(value_width)} |"
puts "+#{'-' * (key_width + 2)}+#{'-' * (value_width + 2)}+#{'-' * (value_width + 2)}+"
# Print the table rows
hash1.each do |key, value|
puts "| #{key.to_s.ljust(key_width)} | #{value.to_s.ljust(value_width)} | #{hash2[key].to_s.ljust(value_width)} |"
end
# Print the table footer
puts "+#{'-' * (key_width + 2)}+#{'-' * (value_width + 2)}+#{'-' * (value_width + 2)}+"
end