const counter = str => {
return [...str].reduce((total, letter) => {
if (!total[letter]) {
return {
...total,
[letter]: 1
}
} else {
return {
...total,
[letter]: total[letter] + 1
}
}
}, {});
};
console.log(counter("aabsssd"));