Created
December 15, 2018 20:24
-
-
Save zgfif/107e0c0e900749a1af3d3690577180ac to your computer and use it in GitHub Desktop.
Реалізувати програму, яка буде приймати аргументом рядок (String) і рахувати скільки разів зустрічається кожна літера в цьому рядку.
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 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