Nodejs Array Map map(testFunction)

Here you can find the source of map(testFunction)

Method Source Code

Array.prototype.map = function(testFunction){
   var result = [];
   this.forEach(function(item){
      result.push(testFunction(item));//  ww w. j a  v a  2s. c o m
   })
   return result;
}

Related

  1. map(projectionFunction)
    Array.prototype.map = function(projectionFunction) {
      var results = [];
      this.forEach(function(itemInArray) {
        results.push(projectionFunction(itemInArray));
      });
      return results;
    };
    
  2. map(projectionFunction)
    Array.prototype.map = function(projectionFunction) {
      var results = [];
      this.forEach(function(itemInArray) {
        results.push(projectionFunction(itemInArray));
      });
      return results;
    };
     var answer = JSON.stringify([1,2,3].map(function(x) { return x + 1; })) === '[2,3,4]';
     console.log(answer);
    ...
    
  3. map(projectionFunction)
    Array.prototype.map = function(projectionFunction) {
      var results = [];
      this.forEach(itemInArray => results.push(projectionFunction(itemInArray)) );
      return results;
    };
    
  4. map(projectionFunction)
    Array.prototype.map = function (projectionFunction) {
      var results = [];
      this.forEach(function (itemInArray) {
        results.push(projectionFunction(itemInArray));
      });
      return results;
    };
    
  5. map(projectionFunction)
    Array.prototype.map = function(projectionFunction) {
      var results = [];
      this.forEach(function(itemInArray) {
      });
      return results;
    };
    JSON.stringify(
      [1,2,3].map(function(x) {
        return x + 1;
    ...
    
  6. map(transform)
    Array.prototype.map = function (transform) {
      let mappedArray = [];
      const len = this.length;
      for (let i = 0; i < len; i += 1) {
        mappedArray.push(transform(this[i], i, this));
      return mappedArray;
    };
    
  7. map(transformer)
    Array.prototype.map = function(transformer) {
      var result = []
      for ( var i = 0; i < this.length; i++) {
        result.push(transformer(this[i]));
      return result;
    
  8. 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
    ...
    
  9. 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);
    ...