Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

count value a to b character javascript

function count (string) {  
  var count = {};
  string.split('').forEach(function(s) {
     count[s] ? count[s]++ : count[s] = 1;
  });
  return count;
}
Comment

count value a to b character javascript

 const recorrences = ['a', 'b', 'c', 'a', 'b','a']
                .map(i => !!~i.indexOf('a'))
                .filter(i => i)
                .length;
console.log(`recorrences ${recorrences}`) 
//recorrences 3
Comment

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 }
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to remove character from string in javascript 
Javascript :: add an array to another array javascript 
Javascript :: js get last element of array 
Javascript :: how to create an array in node js 
Javascript :: leaflet each layer 
Javascript :: javascript eval passing variable 
Javascript :: js exit function 
Javascript :: javascript take last element of array 
Javascript :: node js load css file 
Javascript :: push an property and value to an object in javascript 
Javascript :: js var audio = new audio 
Javascript :: get value from json object in javascript 
Javascript :: get Two digit number js 
Javascript :: Vue.use is not a function 
Javascript :: angular cors issue 
Javascript :: convert int to float in javascript 
Javascript :: react native gradient 
Javascript :: react-native eject not working 
Javascript :: deserialize json jquery 
Javascript :: urlencoded limit nodejs 
Javascript :: clean url javascript 
Javascript :: angularjs round to 2 decimal places input 
Javascript :: how to change the color of a console.log in javascript 
Javascript :: react native environment variables 
Javascript :: replace componentwillmount with hooks 
Javascript :: js create object from array 
Javascript :: vue fix eslint error 
Javascript :: set css var with javascript 
Javascript :: javascript random element from array 
Javascript :: localstorage vs sessionstorage 
ADD CONTENT
Topic
Content
Source link
Name
1+3 =