Answers for "how to count occurrences of a character in string javascript"

0

count value a to b character javascript

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 }
Posted by: Guest on June-20-2020

Code answers related to "how to count occurrences of a character in string javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language