js-zip
Version:
Implement zip function of python
84 lines (78 loc) • 1.35 kB
Markdown
> Implement zip function of python, used to transform a matrix,such as:
```js
[
[],
[],
[]
]
```
to:
```js
[
[],
[],
[]
]
```
Each row must be **iteratable object**,such as Array,String
> npm i -S js-zip
- Multi Arrays
```js
const JsZip = require('js-zip');
const a = [1,2,3];
const b = [4,5,6];
const c = [7,8,9];
const matrix = JsZip(a, b, c);
```
output matrix is:
```js
[
[],
[],
[]
]
```
- Matrix
```js
const JsZip = require('js-zip');
const arr = [[1,2,3], [4,5,6], [7,8,9]];
const matrix = JsZip(...arr);
```
output matrix is:
```js
[
[],
[],
[]
]
```
- String List
```js
const JsZip = require('js-zip');
const arr = ['abc', 'def', 'xyz'];
const maxtrix = JsZip(...arr);
```
output matrix is:
```js
[
[ 'a', 'd', 'x' ],
[ 'b', 'e', 'y' ],
[ 'c', 'f', 'z' ]
]
```
- Use <script> label
```js
<script type="text/javascript" src="../dist/js-zip.min.js"></script>
<script type="text/javascript">
(function() {
var a = [1,2,3];
var b = [4,5,6];
const maxtrix = JsZip(a,b);
})();
</script>
```
MIT@[ZiQiangWang](https://github.com/ZiQiangWang).