Created
August 29, 2017 03:19
-
-
Save ericabell/cf38fb26b09207310529ec2b26613f52 to your computer and use it in GitHub Desktop.
I think the map method runs synchronously
This file contains hidden or 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
let myBigArray = [] | |
for(let i=0; i<2000000; i++) { | |
myBigArray.push(i); | |
} | |
console.log('Done filling the array.'); | |
let myNewBigArray = myBigArray.map( (e) => { | |
return e+2; | |
}); | |
// if map ran *asynchronously* then when we try to console.log the last element | |
// of myNewBigArray, we would get an error. | |
console.log(`Last element of myNewBigArray: ${myNewBigArray[myNewBigArray.length-1]}`); | |
console.log('Done with map'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment