Here you can find the source of map(projectionFunction)
//http://reactivex.io/learnrx/ //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)); });// w w w. ja v a 2s.c o m return results; }; console.log(JSON.stringify([1,2,3].map(function(x) { return x + 1; }))) //=== '[2,3,4]'
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; };
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; };
Array.prototype.map = function (projectionFunction) { var results = []; this.forEach(function (itemInArray) { results.push(projectionFunction(itemInArray)); }); return results; };