Javascript Array myMap(blk)

Description

Javascript Array myMap(blk)



Array.prototype.myMap = function(blk){
  var mapped = [];
  this.myEach(function(elem){
    mapped.push(blk(elem));/*from  ww w  . j  av a 2 s  .c om*/
  });

  return mapped;
};

// var arr = [1,2,3,4];
// arr.myMap(function (el) {
//   console.log(el);
// });
// console.log(arr);



PreviousNext

Related