← Challenges

Lua: Word Count

Write solve(s) that returns the number of whitespace-separated words in the string s. Use a Lua pattern with gmatch rather than splitting on a single space, so runs of extra whitespace don't produce empty "words".

Examples

  • solve("hello world")2
  • solve("Lua is fun")3