reduct-char-sum
字符频率统计
const a = 'abscdemoademoethiaaadmeodihtissdoeoe';
const res = {};
// loop
for (char in a) {
if (!res[a[char]]) {
res[a[char]] = 1;
} else {
res[a[char]]++;
}
}
// reduce
// tips use split('') to generate array
const ress = a.split('').reduce((res, char) => {
res[char]++ || (res[char] = 1);
return res;
}, {});