Easy
JavaScript Word Counter Not Handling Multiple Spaces and Punctuation Correctly
You are building a feature where a user can input text, and the app will count the number of words. You need to improve the word counting function, but there's an issue with how the input is being processed. What’s the problem with this code?
1const countWords = text => {2 return text.split(' ').filter(word => word.length > 0).length;3};45console.log(countWords('Hello there! How are you doing today?'));6console.log(countWords(' This is a test. '));