Skip to content

togakangaroo/gimgen-preso

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 

Repository files navigation

implement zip

collection 1collection 2collection 3result
1afish(1, a, fish)
2bpita(2, b, pita)
3cheese
4
const zip = function * (...collections) {
    const iterators = collections.map(c => c[symbol.iterator]());
    while(true) {
        const nexts = iterators.map(i => i.next())
        if(nexts.some(n => n.done))
            return
        yield nexts.map(n => n.value)
    }
}

const col = (index) => example.map(x => x[index]).filter(x => x)

return [...zip(col(0), col(1), col(2) )]

implement zip-longest

collection 1collection 2collection 3result
1afish(1, a, fish)
2bpita(2, b, pita)
3cheese(3, _, cheese)
4(4, _, _)
const zipLongest = function * (padWith, ...collections) {
    const iterators = collections.map(c => c[Symbol.iterator]());
    while(true) {
        const nexts = iterators.map(i => i.next())
        if(nexts.every(n => n.done))
            return
        yield nexts.map(n => n.done ? padWith : n.value)
    }
}

const col = (index) => example.map(x => x[index]).filter(x => x)

return [...zipLongest(`_`, col(0), col(1), col(2) )]

Releases

No releases published

Packages

No packages published

Languages