Nodejs Array Map mapper(callback)

Here you can find the source of mapper(callback)

Method Source Code

Array.prototype.mapper = function(callback){
    var arr = [];
    //from  w  w  w .jav  a  2  s  .  co  m
    for (var i = 0; i < this.length; i++)
        callback(this[i]);
        
    return arr;
};




var arr = [1, 2, 3];
Array.prototype.mapper = function(callback){
    for (var i = 0; i < this.length; i++)
        this[i] = callback(this[i]);
};

arr.mapper();
console.log(arr) // -> [2,4,6]

Related

  1. map2(projection)
    const stocks= [
      {symbol: 'XFX', price: 240.22, volume: 23432},
      {symbol: 'TNZ', price: 332.19, volume: 234},
      {symbol: 'JXJ', price: 120.22, volume: 5323},
    ]
    Array.prototype.map2= function(projection) {
      let results= []
      this.forEach(item => results.push(projection(item)))
      return results
    ...
    
  2. mapByTwo(fun /*, thisp*/)
    Array.prototype.mapByTwo = function(fun ) {
      if (typeof fun != "function")
        throw new TypeError();
      var len = this.length >>> 0;
      var thisp = arguments[1];
      var k = 0;
      var A = new Array(Math.ceil(len/2));
      if (len/2 < A.length) {
        this.push(null);
    ...
    
  3. mapMe(func)
    Array.prototype.mapMe = function (func) {
      var arr = this, result = [];
      for (var i = 0; i < arr.length; i++) {
        result.push(func(arr[i]));
      return result;
    };
    
  4. mapValues(value)
    Array.prototype.mapValues = function(value) { 
        return this.map(function(e) { 
            return e[value] 
        })
    
  5. mapp(callback)
    Array.prototype.mapp = function(callback) {
      var newArray = [];
      for(var i = 0; i < this.length; i++){
        newArray.push(callback(this[i]));
      return newArray;
    var x = [1,2,3];
    x.mapp(function(ele) {
    ...
    
  6. mapx(f,t)
    Array.prototype.mapx=function(f,t){
      var b=this.length,a=new Array(b);
      for(var i=0;i<b;i++){
        a[i]=f.call(t,this[i],i,this);
      return a;