count characters in string
# count characters iterative
def count_chars(s)
count = Hash.new(0)
s.split("").each do |x|
count[x] += 1
end
count
end
# count characters functional
s.chars.map {|c| [c, s.chars.count(c)] }.to_h
count characters in string
# count characters iterative
def count_chars(s)
count = Hash.new(0)
s.split("").each do |x|
count[x] += 1
end
count
end
# count characters functional
s.chars.map {|c| [c, s.chars.count(c)] }.to_h
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us