Here you can find the source of map(projectionFunction)
/*/*from w w w. ja va2 s .c o m*/ Exercise 4: Implement map() To make projections easier, let's add a map() function to the Array type. Map accepts the projection function to be applied to each item in the source array, and returns the projected array. */ Array.prototype.map = function(projectionFunction) { var results = []; this.forEach(function(itemInArray) { results.push(projectionFunction(itemInArray)); }); return results; }; // JSON.stringify([1,2,3].map(function(x) { return x + 1; })) === '[2,3,4]'
Array.prototype.map = function(mapper) { var result = []; for (var i = 0; i < this.length; ++i) { result.push(mapper(this[i])); return result; };
Array.prototype.map = function(mappingRelation){ return this.reduce(function(accumulator, value){ return accumulator.concat(mappingRelation(value)); }, []);
Array.prototype.map = function(projectionFunction) { var reuslts = []; this.forEach(function(itemInArray){ results.push(projectionFunction(itemInArray)); }) return results;
Array.prototype.map = function(projectionFunction) { var results = []; this.forEach(function(itemInArray) { results.push(itemInArray+1); }); console.log(results); return results; };
Array.prototype.map = function (projectionFunction) { var results = []; this.forEach(function (itemInArray) { results.push(projectionFunction(itemInArray)); }); return results; };
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; })))
Array.prototype.map = function(projectionFunction) { var results = []; this.forEach(function(itemInArray) { results.push(projectionFunction(itemInArray)); }); return results; };
Array.prototype.map = function(projectionFunction) { var results = []; this.forEach(function(itemInArray) { results.push(projectionFunction(itemInArray)); }); return results; }; var answer = JSON.stringify([1,2,3].map(function(x) { return x + 1; })) === '[2,3,4]'; console.log(answer); ...
Array.prototype.map = function(projectionFunction) { var results = []; this.forEach(itemInArray => results.push(projectionFunction(itemInArray)) ); return results; };