Javascript Function ..... Common Mistake ...... Need Help!

Use the function below to write your own

 /* Array.prototype.map equivalent to double each number
 */
var items = [1,5,8,2,6];
function map(collection, fn) {
   
}
var mapped = map(items, function (item) {
    return item * 2;
});
console.log(mapped);

You want to return a new array inside map and push the result of fn(item) for each item in the array.

1 Like

Thanks a lot @markbrown4 … I am trying to do that … Help is appreciated !!

Give it a try and let us know how you go, giving you the answer won’t help you learn.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.