Skip to content
This repository has been archived by the owner on Dec 30, 2023. It is now read-only.

strong-roots-capital/zip

Repository files navigation

zip Build status npm version codecov

Stitch together two arrays by like-index

Why yet-another zip?

I needed a zip that

  • doesn't modify Array prototype
  • is strongly-typed
  • supports currying

Install

npm install @strong-roots-capital/zip

Use

import zip from '@strong-roots-capital/zip'

/* Basic use */
const a = [1, 2, 3]
const b = ['a', 'b', 'c']
console.log(zip(a, b))
//=>[ [ 1, 'a' ], [ 2, 'b' ], [ 3, 'c' ] ]

const zipWithA = zip(a.reverse())
console.log(zipWithA(b))
//=>[ [ 3, 'a' ], [ 2, 'b' ], [ 1, 'c' ] ]

Note that the output array will have the same length as a.

Related