So here's the challenge: create a function that takes an array of strings and outputs an object. The keys in the object should represent the number of characters in each string, while the values should indicate how many times a string with that amount of characters appears.
I hit a roadblock while working on this problem and could really use some assistance. I've tried every search engine query I can think of but haven't had any luck so far. Any help you can provide would be greatly appreciated!
The expected output should resemble this example: characterCount(['apple', 'berry', 'cherry']) // {5:2, 6:1}
function characterCount(arr){
var newObj = {};
var valueMax = 0;
var currentValue = 0;
for(var i=0; i < arr.length; i++){
var key = arr[i].length;
for(var z=0; z < arr.length; z++){
if (arr[z].length === arr[i].length){
currentValue ++;
if (currentValue > valueMax){
valueMax = currentValue;
}
}
}
newObj.key = "valueMax";
}
return newObj;
}