📜  计数值 a 到 b 字符 javascript 代码示例

📅  最后修改于: 2022-03-11 15:03:31.647000             🧑  作者: Mango

代码示例3
let counter = str => {
  return str.split('').reduce((total, letter) => {
    total[letter] ? total[letter]++ : total[letter] = 1;
    return total;
  }, {});
};

counter("aabsssd"); // => { a: 2, b: 1, s: 3, d: 1 }