a = %w(hi this is rajkumar this is uthayaa this is testing for repeat and repeat string)
b = Hash.new 0
a.each do |w|
b[w] += 1
end
puts b
output: => {"hi"=>1, "this"=>3, "is"=>3, "rajkumar"=>1, "uthayaa"=>1, "testing"=>1, "for"=>1, "repeat"=>2, "and"=>1, "string"=>1}
b = Hash.new 0
a.each do |w|
b[w] += 1
end
puts b
output: => {"hi"=>1, "this"=>3, "is"=>3, "rajkumar"=>1, "uthayaa"=>1, "testing"=>1, "for"=>1, "repeat"=>2, "and"=>1, "string"=>1}
No comments:
Post a Comment