Stretch, Strings
Count the words
The task
Count the words in a piece of text. There may be extra spaces at the start, at the end or between words, and the text may be empty.
Write a function called countWords.
Tests
| Call | Expected | Yours |
|---|---|---|
countWords("the cat sat") |
3 |
not run |
countWords(" spaced out ") |
2 |
not run |
countWords("") |
0 |
not run |
countWords("one") |
1 |
not run |
solution.js
Tab indents. To leave the editor, press Escape, then Tab.
Output
Run prints what your code prints. Run the tests to check your function.