Nodejs Array Map map(projectionFunction)

Here you can find the source of map(projectionFunction)

Method Source Code

Array.prototype.map = function(projectionFunction) {
   var results = [];
   this.forEach(function(itemInArray) {

      // ------------ INSERT CODE HERE! ----------------------------
      // Apply the projectionFunction to each item in the array and add
      // each result to the results array.
      // Note: you can add items to an array with the push() method.
      // ------------ INSERT CODE HERE! ----------------------------
    results.push(projectionFunction(itemInArray));
   });//from ww w .  ja va  2 s .  co m

   return results;
};

 var answer = JSON.stringify([1,2,3].map(function(x) { return x + 1; })) === '[2,3,4]';

 console.log(answer);

Related

  1. map(projectionFunction)
    Array.prototype.map = function(projectionFunction) {
      var results = [];
      this.forEach(function(itemInArray) {
        results.push(itemInArray+1);
      });
      console.log(results);
      return results;
    };
    
  2. map(projectionFunction)
    Array.prototype.map = function (projectionFunction) {
      var results = [];
      this.forEach(function (itemInArray) {
        results.push(projectionFunction(itemInArray));
      });
      return results;
    };
    
  3. map(projectionFunction)
    Array.prototype.map = function(projectionFunction) {
      var results = [];
      this.forEach(function(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;
    };
    console.log(JSON.stringify([1,2,3].map(function(x) { return x + 1; }))) 
    
  5. map(projectionFunction)
    Array.prototype.map = function(projectionFunction) {
      var results = [];
      this.forEach(function(itemInArray) {
        results.push(projectionFunction(itemInArray));
      });
      return results;
    };
    
  6. map(projectionFunction)
    Array.prototype.map = function(projectionFunction) {
      var results = [];
      this.forEach(itemInArray => results.push(projectionFunction(itemInArray)) );
      return results;
    };
    
  7. map(projectionFunction)
    Array.prototype.map = function (projectionFunction) {
      var results = [];
      this.forEach(function (itemInArray) {
        results.push(projectionFunction(itemInArray));
      });
      return results;
    };
    
  8. 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;
    ...
    
  9. map(testFunction)
    Array.prototype.map = function(testFunction){
      var result = [];
      this.forEach(function(item){
        result.push(testFunction(item));
      })
      return result;