Count total characters in an Array of Strings in Ruby?
ruby
Solution
Wing's Answer will work, but just for fun here are a few alternatives
['peter' , 'romeo' , 'bananas', 'pijamas'].inject(0) {|c, w| c += w.length }
or
['peter' , 'romeo' , 'bananas', 'pijamas'].join.length
The real issue is that `string.count` is not the method you're looking for. (Docs)
Problem
How would I count the total number of characters in an array of strings in Ruby? Assume I have the following: ``` array = ['peter' , 'romeo' , 'bananas', 'pijamas'] ``` I'm trying: ``` array.each do |counting| puts counting.count "array[]" end ``` but, I'm not getting the desired result. It appears I am counting something other than the characters. I searched for the count property but I haven't had any luck or found a good source of info. Basically, I'd like to get an output of the total of characters inside the array.,