Nodejs Array Map map(grade)

Here you can find the source of map(grade)

Method Source Code

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));//from   w  w  w  . j ava2  s  . c o  m
   });
   return result;
};

var a = school.map(function(x) {
   return x + 12;
});

console.log(a);

Related

  1. map(fun /*, thisp*/)
    Array.prototype.map = Array.prototype.map || function(fun ) {
        var len = this.length >>> 0;
        if (typeof fun != "function") {
            throw new TypeError();
        var res = new Array(len);
        var thisp = arguments[1];
        for (var i = 0; i < len; i++) {
            if (i in this) {
    ...
    
  2. map(func)
    Array.prototype.map = function(func){
      var result = [];
      forEach(this, function (element) {
        result.push(func(element));
      });
      return result;
    
  3. map(func)
    Array.prototype.map = Array.prototype.map || function (func) {
        array = [];
        utility.scan(this, function (item) { array.push(func(item)); });
        return array;
    };
    
  4. map(func)
    Array.prototype.map = function(func) {
      var results = [];
      for(var i = 0; i < this.length; i++) {
        var result = func(this[i]);
        results.push(result);
      return results;
    
  5. 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;
    };
    
  6. map(handler)
    Array.prototype.map = function (handler) {
        var result = []
        for (var i = 0; i < this.length; i++) {
            result.push(handler(this[i]))
        return result
    
  7. 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;
    };
    
  8. 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;
    };
    ...
    
  9. map(mapper)
    Array.prototype.map = function(mapper) {
       var result = [];
       for (var i = 0; i < this.length; ++i) {
          result.push(mapper(this[i]));
       return result;
    };