I'm currently working on a project to tally the frequency of emojis within a body of text. For instance:
"I adore 🚀🚀🚀 so much 😍 " -> [{🚀:3}, {😍:1}]
To accomplish this, I've developed a function that calculates the occurrence of characters in a block of text.
function getFrequency(string) {
var freq = {};
for (var i=0; i<string.length;i++) {
var character = string.charAt(i);
if (freq[character]) {
freq[character]++;
} else {
freq[character] = 1;
}
}
return freq;
};
source:
^While the above code functions well, it does not properly identify emoji characters:
{: 1, : 3, : 2}
Furthermore, I would like the output to be a list of json objects each containing one value, rather than a single lengthy json object.