UNPKG

@extra-array/zip

Version:
65 lines (48 loc) 2.02 kB
Combines values from arrays. [:package:](https://www.npmjs.com/package/@extra-array/zip) [:smiley_cat:](https://github.com/orgs/nodef/packages?repo_name=extra-array) [:running:](https://npm.runkit.com/@extra-array/zip) [:vhs:](https://asciinema.org/a/332154) [:moon:](https://www.npmjs.com/package/@extra-array/zip.min) [:scroll:](https://unpkg.com/@extra-array/zip/) [:newspaper:](https://nodef.github.io/extra-array/) [:blue_book:](https://github.com/nodef/extra-array/wiki/) > Similar: [cartesianProduct], [zip]. > This is part of package [extra-array]. [extra-array]: https://www.npmjs.com/package/extra-array <br> ```javascript array.zip(xs, [fm], [ft], [vd]); // xs: arrays // fm: map function (vs, i) // ft: till function (dones) (some) // vd: default value ``` ```javascript const array = require("extra-array"); var x = [1, 2, 3]; var y = [4, 5]; array.zip([x, y]); // [ [ 1, 4 ], [ 2, 5 ] ] (shortest) array.zip([x, y], ([a, b]) => a + b); // [ 5, 7 ] array.zip([x, y], null, array.some); // [ [ 1, 4 ], [ 2, 5 ] ] (shortest) array.zip([x, y], null, array.every, 0); // [ [ 1, 4 ], [ 2, 5 ], [ 3, 0 ] ] (longest) array.zip([x, y], null, array.head, 0); // [ [ 1, 4 ], [ 2, 5 ], [ 3, 0 ] ] (first) ``` <br> <br> ## References - [Data.List.zipWith: Haskell](http://hackage.haskell.org/package/base-4.12.0.0/docs/Data-List.html#v:zipWith) - [List-Extra.zip: elm](https://package.elm-lang.org/packages/elm-community/list-extra/7.1.0/List-Extra#zip) - [zip: Python](https://www.programiz.com/python-programming/methods/built-in/zip) - [itertools.zip_longest: Python](https://docs.python.org/3/library/itertools.html#itertools.zip_longest) - [zip: Ruby](https://apidock.com/ruby/Array/zip) - [_.zip: lodash](https://lodash.com/docs/4.17.15#zip) - [_.zipWith: lodash](https://lodash.com/docs/4.17.15#zipWith) - [Array.zip: sugarjs](https://sugarjs.com/docs/#/Array/zip) [cartesianProduct]: https://github.com/nodef/extra-array/wiki/cartesianProduct [zip]: https://github.com/nodef/extra-array/wiki/zip