Javascript Array map(projectionFunction)
Array.prototype.map = function (projectionFunction) { var results = []; this.forEach(function (itemInArray) { results.push(projectionFunction(itemInArray)); });//from w w w . j a v a2 s.com return results; };
'use strict';/* ww w . j av a2 s.com*/ Array.prototype.map = function(projectionFunction) { var results = []; this.forEach(item => results.push(projectionFunction(item))); return results; };
Array.prototype.map = function(projectionFunction) { var reuslts = []; this.forEach(function(itemInArray){ results.push(projectionFunction(itemInArray)); })/*from w w w . ja v a 2 s . com*/ return results; }
Array.prototype.map = function(projectionFunction) { var results = []; this.forEach(function(itemInArray) { results.push(projectionFunction(itemInArray)); });// w w w. j a v a 2 s . com return results; }; console.log(JSON.stringify([1,2,3].map(function(x) { return x + 1; })) === '[2,3,4]');
Array.prototype.map = function (projectionFunction) { var results = []; this.forEach(function (itemArray) { results.push(itemArray + 1);/*from w w w. j a va2 s. c om*/ }); return results; }; // JSON.stringify([1,2,3].map(function(x) { return x + 1; })) === '[2,3,4]'
Array.prototype.map = function(projectionFunction) { var results = []; this.forEach(itemInArray => results.push(projectionFunction(itemInArray)) ); return results; };