javascript counting characters in a string code example
Example 1: how to check how many strings are in a sentence javascript
function WordCounter (str) {
var words = str.split(" ").length;
return words;
}
// this should work!
Example 2: 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 }