JSFiddle - React, Tailwind, and code Playground
JavaScript
function charCount(str, keepCase) {
if (!keepCase) str = str.toLowerCase();
var obj = {};
for (var i = 0; i < str.length; i++) {
if (!obj[str[i]]) obj[str[i]] = 0;
obj[str[i]]++;
}
return obj;
}
var a = charCount("hello");
var b = charCount("AaBbC")
console.log(a, b);