Skip to content

Instantly share code, notes, and snippets.

View narenderv7's full-sized avatar
🎯
Focusing

Narender Vaddepelly narenderv7

🎯
Focusing
View GitHub Profile
@narenderv7
narenderv7 / flatten.js
Created December 25, 2019 08:54
Flattens Array
function* flatten(array, deep) {
if (deep === undefined) deep = 1
for (const item of array) {
if (Array.isArray(item) && deep > 0) {
yield* flatten(item, deep - 1)
} else {
yield item
}
}
}