Nodejs String Word Count wordCount(char, cs)

Here you can find the source of wordCount(char, cs)

Method Source Code

/**/*w  ww.j av a2  s. com*/
 * Returns count of requested param. 
 *
 * @param {string | number} char is requested string. 
 * @param {Boolean=} cs is case sensitive. 
 * @return {Number} 
 */
String.prototype.wordCount = function(char, cs) {
    if (cs) 
        return this.toLowerCase().split(char.toLowerCase()).length - 1;
    else
        return this.split(char).length - 1;
};

Related

  1. wordCount()
    String.prototype.wordCount = function() {
      return this.words().length;
    };
    
  2. wordCount()
    String.prototype.wordCount = function(){
      var result = this.words();
      return result.length;
    };
    
  3. wordCount()
    String.prototype.wordCount = function() {
      return this.words().length;
    };
    
  4. wordCount()
    String.prototype.wordCount = function() {
        return this.split(/\s+/).length;
    
  5. wordCount()
    String.prototype.wordCount = function() {
      return this.words().length;