function count (string) { var count = {}; string.split('').forEach(function(s) { count[s] ? count[s]++ : count[s] = 1; }); return count; }
const recorrences = ['a', 'b', 'c', 'a', 'b','a'] .map(i => !!~i.indexOf('a')) .filter(i => i) .length; console.log(`recorrences ${recorrences}`) //recorrences 3
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 }