Count Words
STRING
Problem
Given a string text
, return the number of words in it.
Words are defined as sequences of characters separated by spaces. The string can have any number of leading or trailing spaces.
Examples
countWords('Hello world') // 2 countWords(' Counting words in a string ') // 5 countWords('') // 0 countWords(' ') // 0
Loading...