Created
July 7, 2020 15:39
-
-
Save laphilosophia/171cf2ff2792c896f02921640666b175 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
/** | |
* @param {number} range | |
*/ | |
function* generator (range) { | |
let i = 0 | |
while (i < range) { | |
i += 1 | |
yield i | |
} | |
} | |
/** | |
* @param {string | any[]} array | |
*/ | |
function* each (array) { | |
if (!Array.isArray(array)) return | |
if (!array.length || array.length === 1) return | |
let index = 0 | |
while (index < array.length) { | |
yield array[index++] | |
} | |
} | |
const gen1 = generator(10) | |
const gen2 = each([10, 1, 4, 6, 124, 56, 3, 6]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment