Nodejs Array Count valueCount(value)

Here you can find the source of valueCount(value)

Method Source Code

Array.prototype.valueCount = function (value) {
  var count = 0;/*from w w  w  .  j av  a2 s  .  co m*/

  for( var i = 0; i < this.length; i++) {
    if ( this[i] === value) {
      count++;
    };
  };
  return count;
};

Array.prototype.myUniq = function () {
  var uniqArray = [];

  for( var i = 0; i < this.length; i++) {
    if( uniqArray.valueCount(this[i]) === 0  ) {
      uniqArray[uniqArray.length] = this[i];
    };
  };

  return uniqArray;
};

Array.prototype.subsets = function () {
  if (this.length === 0) {
    return this;
  }
  var subs = [];

  for (var i = 0; i < this.length; i++) {
    subs.push(this);
    new_arr = this.slice();
    // console.log(this);
    new_arr.splice(i,1);
    // console.log(new_arr);
    // console.log(new_arr);
    subs.push(new_arr)
    // subs.concat(new_arr.subsets())
  }
  return subs.myUniq();
};
a = [1,2,3]
console.log(a.subsets());

Related

  1. countOf(pValue)
    Array.prototype.countOf = function (pValue){
        var count   = 0;
        var lArray  = this || [];
        var lLength = lArray.length
        for (var i = 0 ; i < lLength; i++){
            if (lArray[i] == pValue){
                count++;
        return count;
    
  2. countType(type)
    Array.prototype.countType = function (type) {
      var count = 0
      for( var i = 0, x = this.length; i < x; i++) {
        if (this[i] === type) {
          count++
      return count
    
  3. element_count()
    Array.prototype.element_count = function(){
      var count = 0;
      for(var i=0; i<this.length; i++){
        if(this[i] != undefined){
          count++;
      return count;
    
  4. first_n(count)
    Array.prototype.first_n=function(count) {
      var a=[];
      for(var i=0;i<count;i++) {
        a.append(this[i]);
      return a;
    
  5. valueCount(value)
    Array.prototype.valueCount = function (value) {
      var count = 0;
      for( var i = 0; i < this.length; i++) {
        if ( this[i] === value) {
          count++;
        };
      };
      return count;
    };
    ...