Javascript Array myMap(fn)

Description

Javascript Array myMap(fn)


Array.prototype.myMap = function(fn) {
  var final = [];
  this.forEach(function (el) {
    final.push(fn(el));/*from w ww .  ja  v a 2  s  . co  m*/
  }

  return final;
};

Javascript Array myMap(fn)

// Implement the Array#map function in JavaScript.

Array.prototype.myMap = function (fn) {
  var final = [];
  this.forEach(function (num) {
    final.push(fn(num));//from w w  w  .  jav  a  2 s . co m
  });
  return final;
};



PreviousNext

Related