Ad
Code
Diff
  • function wordCount(str) {
      return str.replace(/\s/g, '').length ? str.trim().split(/\s+/).length : 0;
    }
    • function wordCount(str) {
    • var words = 1;
    • for(var i = 1; i < str.length; i++) {
    • if(str[i] == " " && str[i - 1] !== " "&& str[i + 1] !== " ") {
    • words++;
    • }
    • }
    • return words;
    • }
    • return str.replace(/\s/g, '').length ? str.trim().split(/\s+/).length : 0;
    • }
Code
Diff
  • function wordCount(str) {
      return str.replace(/\s/g, '').length ? str.trim().split(/\s+/).length : 0;
    }
    • function wordCount(str) {
    • return str.length > 2 ? str.split(' ').length : 1;
    • return str.replace(/\s/g, '').length ? str.trim().split(/\s+/).length : 0;
    • }