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;
} const recorrences = ['a', 'b', 'c', 'a', 'b','a']
.map(i => !!~i.indexOf('a'))
.filter(i => i)
.length;
console.log(`recorrences ${recorrences}`)
//recorrences 3let 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 }
Also in JavaScript:
- javascript new date undefined
- Function in JavaScript that can be called only once
- orm for postgres node js
- how to set disabled flag formgroup angular
- javascript tofixed 2
- create moment duration
- js difference between two numbers
- angular form validation
- js queryselectorall
- Cannot assign to read only property 'value' of object '[object Object]
- call function with id javascript
- node js get file name without extension
- js test if string
- js check if string contains character
- how to get code suggestions for react components
- vendor bundle base js and bootstrap min js conflict
- how to get property names from object using map method react
- run on load js
- jquery closest
- compare strings js
- javascript switch case regex
- update state in react
- jquery script url
- npm react router 6.0.0-alpha.2