Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

frequency of characters in a string in javascript

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"));
Source by thewebdev.info #
 
PREVIOUS NEXT
Tagged: #frequency #characters #string #javascript
ADD COMMENT
Topic
Name
7+3 =