freeCodeCamp Challenge Guide: Iterate over Arrays with map

freeCodeCamp Challenge Guide: Iterate over Arrays with map
0

#1

Using map is the best way to iterate through an array or object. Map uses a function to pretty much do whatever you want it to do. It will pass each value to the callback function.

//Use map to add three to each value in the array
var array = [1,2,3,4,5];

array = array.map(function(val){
  return val + 3;
});

#2

Hello campers,here is how i did it:

var oldArray = [1,2,3,4,5];

// Only change code below this line.

var newArray = oldArray.map(function(val) {
return val + 3;
});

console.log(oldArray);
console.log(newArray);


#3

Hey this should work but it is not passing all tests!

var oldArray = [1,2,3,4,5];

// Only change code below this line.
var newArray = Array.prototype.map.call(oldArray,function(i,v){
return i+3;
});