Реалізувати програму, яка буде приймати аргументом рядок (String) і рахувати скільки разів зустрічається кожна літера в цьому рядку.
def count_letters(text) | |
array = [] | |
text = text.downcase | |
text.each_char do |char| | |
if char =~ /[A-Za-z]+/ | |
count = text.count(char) | |
array << [char, count] | |
end | |
end | |
array = array.uniq | |
array.sort! { |a, b| b[1] <=> a[1] } | |
end | |
text = ARGV.first | |
p count_letters(text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment