Solution
function countStringOccurrences(str) {
let occurrence = {};
Array.from(str).forEach(char => {
let currentCount = occurrence[char] || 0;
occurrence[char] = currentCount + 1;
});
console.log(occurrence);
return occurrence;
}
countStringOccurrences("hello");
countStringOccurrences("👍😉😉👍");
Result
Object { h: 1, e: 1, l: 2, o: 1 };
Object { 👍: 2, 😉: 2 }