Javascript Array newMap(f)

Description

Javascript Array newMap(f)


Array.prototype.newMap = function (f) {
  return this.reduce(function (result, x) {
    result.push(f(x));//from ww  w  . j  a v  a 2  s  .  c o m
    return result;
  }, []);
}

var arr = [1, 2, 3];
var brr = arr.newMap(function(value) {
  return value + 1;
})

console.log(brr);



PreviousNext

Related