I have the following problem:
Write a function that takes in a list of words, and returns an object that tells you how many times each letter showed up.
So something like this:
var data = ['hat', 'cat', 'dog'];
becomes:
var object = {
'a' : 2,
'h' : 1,
't' : 2,
'c' : 2,
'd' : 1,
'g' : 1
};
My solution thus far has been to:
- Create a function with a blank object.
- Loop through all the elements of the array
These steps aren't working like I think they were:
- Try to loop through the characters of each array element.
- If the character of the array element is undefined in the object, put it in and increment to one. Otherwise if its already there, increment it by one again.
Where am I going wrong? Or am I way off?
jointhe array into a string so you don't have to use two loops.