Nodejs Array Convert to_frequency()

Here you can find the source of to_frequency()

Method Source Code

// Returns a hash (number:frequency) having the numbers as keys and their frequency as values
Array.prototype.to_frequency = function(){
  hashed_picks = {}/*w  w w. j av  a2s  . com*/
  for (var i = 0; i < this.length; i++){
    pick = this[i].toString()
    if (hashed_picks[pick] == undefined){
      hashed_picks[pick] = 1
    }else{
      hashed_picks[pick]++
    }
  }
  
  return hashed_picks
}

Related

  1. toSource(seen)
    Array.prototype.toSource = function(seen){
      var source, i = 0, j = this.length;
      seen = seen || [this];
      source = '[';
      for(;i<j;i++){
        source+= Object.sourceOf(this[i], seen, '[]');
        if( i < j - 1 ) source+= ', ';
      source+= ']';
    ...
    
  2. toStrGen(originStr)
    Array.prototype.toStrGen=function(originStr){
      if(Object.prototype.toString.call(originStr).slice(8,-1)==="Array"){
        return this.map(function(i){
          return originStr.join(i);
        }).reduce(function(m,n){return m+n+'\b'}, "");
    };
    
  3. toUnique()
    Array.prototype.toUnique = function() {
        var dict = {},
            arrayLength = this.length,
            elem,
            i,
            key,
            uniqueArray = [];
        for (i = 0; i < arrayLength; i++) {
            elem = this[i];
    ...
    
  4. toUniqueDictionary(key)
    Array.prototype.toUniqueDictionary = function(key) {
      if (!key)
        key = function(x) { return x.id; };
      var dictionary = {};
      this.forEach(function(item) {
        var currentKey = key(item);
        if (!currentKey)
          return true;
        dictionary[currentKey] = item;
    ...
    
  5. toUpper()
    Array.prototype.toUpper = function() {
      return this.map(function(x) { return x.toUpperCase(); });
    
  6. to_s()
    Array.prototype.to_s = function(){return this.join('');};