var exampleString = 'hi, my name is Lisa Kudrov';
var stringBase = [
'a','b','c','d','e',
'f','g','h','i','j',
'k','l','m','n','o',
'p','q','r','s','t',
'u','v','w','x','y',
'z','_'
];
var countObject = {} ;
function characterCount(word, character) {
var count = 0;
for (var i = 0; i < word.length; i++) {
if (word[i] === character) {
count++;
}
}
return count;
}
for (var i = 0, l = stringBase.length; i < l; i++) {
var currentChar = stringBase[i];
countObject[currentChar] = characterCount(exampleString, currentChar);
}
console.log(countObject);
I need my output to show the letters that exist only. For example: a:1,c:1 and etc... also how can I shortcut this program in a way that when i call the function, i'll be calling characterCount('hi, my name is Lisa Kudrov')