Created
July 17, 2020 02:47
-
-
Save kitsune7/90569d5354b49182a0b3eaf7cc91f521 to your computer and use it in GitHub Desktop.
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
// Playing around with some different ways of doing for loops | |
// `forEachIterableProtocol` was the main toy I got to play with | |
function forEachIterableProtocol (array, action) { | |
for (let i = array[Symbol.iterator](), obj = i.next(); !obj.done; obj = i.next()) { | |
action(obj.value) | |
} | |
} | |
function forEachNormal (array, action) { | |
for (let i = 0; i < array.length; i++) { | |
action(array[i]) | |
} | |
} | |
function forEachIn (array, action) { | |
for (const item in array) { | |
action(item) | |
} | |
} | |
function forEachOf (array, action) { | |
for (const item of array) { | |
action(item) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment