Search
 
SCRIPT & CODE EXAMPLE
 

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"));
Comment

PREVIOUS NEXT
Code Example
Javascript :: js copy paragraph onclick 
Javascript :: change property in array of objects javascript 
Javascript :: how to get element by class name javascript 
Javascript :: node -r dotenv/config 
Javascript :: how to loop through something in node.js 
Javascript :: antd react native 
Javascript :: format javascript date 
Javascript :: cookie options 
Javascript :: getting empty req.body 
Javascript :: includes method javascript 
Javascript :: regex email 
Javascript :: debounce javascript 
Javascript :: js associative array push 
Javascript :: js refresh 
Javascript :: replace each string by another string javascript 
Javascript :: javascript delay action 
Javascript :: reverse method 
Javascript :: what is jquery 
Javascript :: string interpolation in javascript 
Javascript :: how to redirect to a website in react 
Javascript :: unidirectional data flow react 
Javascript :: javascript splice 
Javascript :: to do list local storage javascript 
Javascript :: if variable is string javascript 
Javascript :: regex e-mail 
Javascript :: useLocation 
Javascript :: vue access computed property in data 
Javascript :: javascript getdate 
Javascript :: react native picker 
Javascript :: this.setstate is not a function 
ADD CONTENT
Topic
Content
Source link
Name
4+2 =