Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/brunoimbrizi/array-unflat
https://github.com/brunoimbrizi/array-unflat
Last synced: 17 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/brunoimbrizi/array-unflat
- Owner: brunoimbrizi
- License: mit
- Created: 2020-11-02T22:40:00.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2020-11-03T10:21:04.000Z (about 4 years ago)
- Last Synced: 2024-10-10T21:43:14.072Z (about 1 month ago)
- Language: JavaScript
- Size: 2.93 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
array-unflat
============The opposite of Array.prototype.flat() with depth = 1.
Useful to convert one-dimensional arrays `[x, y, z, x, y, z]` into two-dimensional arrays `[[x, y, z], [x, y, z]]` i.e. for [simplicial complex](https://github.com/mikolalysenko/simplicial-complex).
## Install
```
npm install array-unflat
```## Example
```js
const unflat = require('array-unflat');const arr = [0.2, 0.3, 0.5, -1.8, 2.9, 1.1];
console.log(unflat(arr));
console.log(unflat(arr, 3));
```
Output:```js
[ [0.2, 0.3], [0.5, -1.8], [2.9, 1.1] ]
[ [0.2, 0.3, 0.5], [-1.8, 2.9, 1.1] ]
```## Usage
#### `unflat(arr, size)`
- `arr` the flattened array
- `size` (default `2`) length of the grouped subarrays
**Returns** a two-dimensional array.
## License
MIT, see [LICENSE](LICENSE) for details.