Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

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 }
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #count #character #javascript
ADD COMMENT
Topic
Name
1+1 =