Created
September 26, 2017 11:05
-
-
Save prajapati-parth/d1567f1a796b1e46b32b9b401f8377b4 to your computer and use it in GitHub Desktop.
A simple for loop with caching
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
let items = [ | |
//unknown number of items | |
] | |
// normal for loop | |
// here items.length is calculated each time the loop cycles | |
for (let i=0; i<items.length; i++) { | |
// inside for | |
} | |
// for loop with caching | |
// here iterations is calculated once and the same is used for each cycle | |
for (let i=0, iterations=items.length; i<iterations; i++) { | |
// inside for | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment