# 数组处理模块
数组处理模块提供了数组去重、分块、扁平化、洗牌等常用的数组操作功能。
## 引用方式
### ES6 模块引用
```javascript
import sinma from 'sinmajs';
import { unique, chunk, flatten, shuffle } from 'sinmajs';
```
### CommonJS 引用
```javascript
const sinma = require('sinmajs');
```
### 浏览器引用
```html
<script src="https://unpkg.com/sinmajs@latest/dist/sinma.min.js"></script>
```
## API 列表
### unique(arr) - 数组去重
```javascript
sinma.unique([1, 2, 2, 3, 3]); // [1, 2, 3]
sinma.unique(['a', 'b', 'a']); // ['a', 'b']
```
### chunk(arr, size) - 数组分块
```javascript
sinma.chunk([1, 2, 3, 4, 5], 2); // [[1, 2], [3, 4], [5]]
sinma.chunk([1, 2, 3, 4], 3); // [[1, 2, 3], [4]]
```
### flatten(arr, depth) - 数组扁平化
```javascript
sinma.flatten([1, [2, 3], [4, [5]]], 1); // [1, 2, 3, 4, [5]]
sinma.flatten([1, [2, [3, [4]]]], 2); // [1, 2, 3, [4]]
```
### shuffle(arr) - 数组洗牌
```javascript
sinma.shuffle([1, 2, 3, 4, 5]); // [3, 1, 5, 2, 4] (随机顺序)
```
## 使用范例
```javascript
// 商品分页显示
function paginateProducts(products, pageSize = 10) {
return sinma.chunk(products, pageSize);
}
// 标签去重
function cleanTags(tags) {
return sinma.unique(tags.map(tag => tag.toLowerCase()));
}
// 多维数组处理
function processNestedData(data) {
return sinma.flatten(data, 2).filter(item => item != null);
}
// 随机抽样
function randomSample(array, count) {
return sinma.shuffle(array).slice(0, count);
}
```
详细文档请参考完整版说明...
