1var str = "Hello Lewes";
2var ch = 'e';
3
4var count = str.split("e").length - 1;
5console.log(count);
6
7/*
8 Output: 3
9*/
10
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 }