Last active
January 24, 2017 22:04
-
-
Save davodey/d1e8656e5d487f2dfde1fd55b3d290bd to your computer and use it in GitHub Desktop.
Example using the ES6 map helper.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var numbers = [1,2,3]; | |
var doubledNumbers = []; | |
// want to move away from this | |
for (var i = 0; i < numbers.length; i++) { | |
doubledNumbers.push(numbers[i] * 2); | |
} | |
// creates a new array with values returned from function | |
var doubled = numbers.map(function(number){ | |
return number * 2 | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment