Nodejs Utililty Methods String Word Count

List of utility methods to do String Word Count

Description

The list of methods to do String Word Count are organized into topic(s).

Method

wordCount()
String.prototype.wordCount = function () {
    var initialBlanks = /^\s+/;
    var leftTrimmed = this.replace(initialBlanks, "");
    var words = leftTrimmed.split(/\s+/);
    if (!words[words.length-1])  words.pop();
    return words.length;
};
wordCount()
String.prototype.wordCount = function() {
  return this.words().length;
};
wordCount()
String.prototype.wordCount = function(){
  var result = this.words();
  return result.length;
};
wordCount()
String.prototype.wordCount = function() {
  return this.words().length;
};
wordCount()
String.prototype.wordCount = function() {
    return this.split(/\s+/).length;
wordCount()
String.prototype.wordCount = function() {
  return this.words().length;
wordCount(char, cs)
String.prototype.wordCount = function(char, cs) {
    if (cs) 
        return this.toLowerCase().split(char.toLowerCase()).length - 1;
    else
        return this.split(char).length - 1;
};