1function count (string) {
2 var count = {};
3 string.split('').forEach(function(s) {
4 count[s] ? count[s]++ : count[s] = 1;
5 });
6 return count;
7}
1 const recorrences = ['a', 'b', 'c', 'a', 'b','a']
2 .map(i => !!~i.indexOf('a'))
3 .filter(i => i)
4 .length;
5console.log(`recorrences ${recorrences}`)
6//recorrences 3
1let counter = str => {
2 return str.split('').reduce((total, letter) => {
3 total[letter] ? total[letter]++ : total[letter] = 1;
4 return total;
5 }, {});
6};
7
8counter("aabsssd"); // => { a: 2, b: 1, s: 3, d: 1 }