Skip to content

Instantly share code, notes, and snippets.

@Git-I985
Created March 4, 2023 22:15
Show Gist options
  • Save Git-I985/775125efd0a14776fd04e9f3e32b9bb1 to your computer and use it in GitHub Desktop.
Save Git-I985/775125efd0a14776fd04e9f3e32b9bb1 to your computer and use it in GitHub Desktop.
JS Words count
export default (_words) => {
const words = _words.split(' ').map(word => word.toLowerCase()).filter(Boolean);
return [...new Set(words)].reduce((acc, word) => ({ ...acc, [word]: words.filter(_word => _word === word).length}), {})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment