Skip to content

Instantly share code, notes, and snippets.

@zgfif
Created December 15, 2018 20:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zgfif/107e0c0e900749a1af3d3690577180ac to your computer and use it in GitHub Desktop.
Save zgfif/107e0c0e900749a1af3d3690577180ac to your computer and use it in GitHub Desktop.
Реалізувати програму, яка буде приймати аргументом рядок (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