Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/**
* @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