Last active
December 16, 2015 19:50
-
-
Save KoryNunn/5488215 to your computer and use it in GitHub Desktop.
A simplified forEach loop that's faster than Array.forEach
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
function fastEach(items, callback) { | |
for (var i = 0; i < items.length && !callback(items[i], i, items);i++) {} | |
return items; | |
} | |
module.exports = fastEach; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Any value in caching the items length? This is sometimes recommend in performance optimisations. Difference will be minimal, but still, you don't want somebody making a
fastereach
module ;)