I'm currently facing an issue with the following task:
Create a function that accepts a list of words and returns an object indicating how many times each letter appears.
For example:
var data = ['hat', 'cat', 'dog'];
should return:
var object = {
'a' : 2,
'h' : 1,
't' : 2,
'c' : 2,
'd' : 1,
'g' : 1
};
My approach so far involves:
- Creating a function with an empty object.
- Iterating through each word in the array.
However, my current implementation is not yielding the expected results. Here's what I've tried:
- Attempting to loop through each character of every word.
- If a character is not present in the object, adding it and setting the count to one. If it already exists, increment the count by one.
I'm unsure where I'm going wrong. Any thoughts or suggestions would be greatly appreciated.