Nodejs String Count count(c)

Here you can find the source of count(c)

Method Source Code

String.prototype.count=function(c) { 
  var result = 0, i = 0;
  for(i;i<this.length;i++)if(this[i]==c)result++;
  return result;// w ww.j av a  2s. c  o  m
};

function commonCharacterCount(s1, s2) {
    var chars = [];
    var total = 0;
    for(var i = 0; i < s1.length; i++){
        if(chars.indexOf(s1[i]) == -1 ){
            chars.push(s1[i]);
        }
    }

    for(var i = 0; i < chars.length; i++){
        total += Math.min(s1.count(chars[i]), s2.count(chars[i]));
    }

    return total;
}


var s1 = "aabcc";
var s2 = "adcaa";
console.log(commonCharacterCount(s1, s2));

Related

  1. count()
    var a = new String();
    var b = new String("Hello World");
    var c = new String("ABC");
    String.prototype.count = function() { return this.length; }
    result = a=="" && b=="Hello World" && c.count()==3;
    
  2. count(c)
    String.prototype.count = function(c) {
      var count = 0;
      for(var i = 0; i < this.length; i += 1) {
        if(this[i] === c) { count += 1; }
      return count;
    };
    
  3. count(s1)
    String.prototype.count=function(s1) {   
        return (this.length - this.replace(new RegExp(s1,"g"), '').length) / s1.length;  
    
  4. count(s1)
    String.prototype.count=function(s1) { 
        return (this.length - this.replace(new RegExp(s1,"g"), '').length) / s1.length;
    String.prototype.trunc = String.prototype.trunc ||
    function(n){
      return this.length>n ? this.substr(0,n-1)+'...' : this;
    };
    Array.prototype.remove = function(from, to) {
      var rest = this.slice((to || from) + 1 || this.length);
    ...
    
  5. count(string)
    String.prototype.count = function(string) {
      return this.split(string).length - 1;
    };
    
  6. countAll(letter)
    String.prototype.countAll = function (letter) {
      var letterCount = 0
      for (var i = 0; i < this.length; i++) {
        if (this.charAt(i).toUpperCase() == letter.toUpperCase()){
          letterCount++
      return letterCount
    var sen = 'Come on, get up and fight'
    console.log(sen.countAll('o'))