Last active
November 21, 2015 12:08
-
-
Save pangers/00ea9742e0a869506ad8 to your computer and use it in GitHub Desktop.
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 array = [1, 2, 3, 4]; | |
//Imperative method | |
var newArray = []; | |
for (var i = 0; i < array.length; i++) { | |
var temp = array[i]; | |
temp = temp + 1; | |
newArray.push(temp); | |
} | |
console.log(newArray); //[2, 3, 4, 5] | |
//Functional method | |
var newerArray array.map((element) => { | |
return element + 1; | |
}); | |
console.log(newerArray); //[2, 3, 4, 5] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment