JSFiddle - React, Tailwind, and code Playground
by mariocatch
JavaScript
var superCounter = function(str) {
var spacesRegex = new RegExp(/\s/g);
var wordsRegex = new RegExp(/\S+/g);
return counterObj = {
spaces: spacesRegex.test(str) ? str.match(spacesRegex).length : 0,
words: wordsRegex.test(str) ? str.match(wordsRegex).length : 0,
chars: str.length
};
};
console.log(superCounter("Count me in ok?"));