Ad
Code
Diff
  • function wordCount(str) {
    // error on no matches.
    // also, are there any other characters besides \w and - that shouldn't break words?
      return str.match(/[\w-]+/g).length;
    }
    
    • function wordCount(str) {
    • return str.split(/\s/g).filter(x => x.length > 0).length;
    • // error on no matches.
    • // also, are there any other characters besides \w and - that shouldn't break words?
    • return str.match(/[\w-]+/g).length;
    • }