Nodejs Array Map map(mapper)

Here you can find the source of map(mapper)

Method Source Code

/** javascript.js: manual implementations of common javascript methods that 
  * are not natively available in yate's implementation.
  * /* w  ww.  j  a  v  a2 s .  c om*/
  * Cellular Search and Rescue - Cellular Sensor BTS
  *   Copyright (C) 2017 Microsoft
  * 
  * This file is part of cell-sar/the Yate-BTS Project http://www.yatebts.com
  * 
  * cell-sar is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation, either version 2 of the License, or
  * (at your option) any later version.
  * 
  * cell-sar is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  * 
  * You should have received a copy of the GNU General Public License
  * along with cell-sar.  If not, see <http://www.gnu.org/licenses/>.
  */

Array.prototype.map = function(mapper) {
   var result = [];
   for (var i = 0; i < this.length; ++i) {
      result.push(mapper(this[i]));
   }
   return result;
};

Related

  1. map(func)
    Array.prototype.map = function(func) {
        var length = this.length;
        var result = [];
        for ( var i = 0; i < length; i++ ) {
            result.push( func(this[i]) );
        return result;
    };
    
  2. map(grade)
    var school = [1, 2, 3, 4, 5, 6, 7, 8, 3, 35, 3, 5];
    Array.prototype.map = function(grade) {
      var result = [];
      this.forEach(function(item) {
        result.push(grade(item));
      });
      return result;
    };
    var a = school.map(function(x) {
    ...
    
  3. map(handler)
    Array.prototype.map = function (handler) {
        var result = []
        for (var i = 0; i < this.length; i++) {
            result.push(handler(this[i]))
        return result
    
  4. map(iterator)
    Array.prototype.map = function(iterator) {
      var results = [];
      for (var i = 0, len = this.length; i < len; i++) {
        results.push(iterator(this[i], i));
      return results;
    };
    
  5. map(iterator, context)
    Array.prototype.map = function (iterator, context) {
        baidu.check("function(,.+)?","baidu.array.map");
        var i, n,
            array = baidu.array([]);
        for (i=0, n=this.length; i < n; i++) {
            array[i] = iterator.call(context || this, this[i], i, this);
        return array;
    };
    ...
    
  6. map(mappingRelation)
    Array.prototype.map = function(mappingRelation){
      return this.reduce(function(accumulator, value){
        return accumulator.concat(mappingRelation(value));
      }, []);
    
  7. map(projectionFunction)
    Array.prototype.map = function(projectionFunction) {
      var reuslts = [];
      this.forEach(function(itemInArray){
        results.push(projectionFunction(itemInArray));
      })
      return results;
    
  8. map(projectionFunction)
    Array.prototype.map = function(projectionFunction) {
      var results = [];
      this.forEach(function(itemInArray) {
        results.push(itemInArray+1);
      });
      console.log(results);
      return results;
    };
    
  9. map(projectionFunction)
    Array.prototype.map = function (projectionFunction) {
      var results = [];
      this.forEach(function (itemInArray) {
        results.push(projectionFunction(itemInArray));
      });
      return results;
    };