DEV Community

Discussion on: What’s your alternative solution? Challenge #36

Collapse
 
hyftar profile image
Simon Landry • Edited

Here's a one liner answer using regex

const countWords = (text) => (text.match(/\b\w+\b/g) || []).length