abbott-methods
Version:
abbott,methods,method,functions,function
26 lines (24 loc) • 756 B
text/typescript
import {typeArray} from '../type/typeArray'
import {aoCleanKeyOne} from './aoCleanKeyOne'
/**
* @description 切片存储在一个新数组
* @param {[]|{}} ao array或object
* @param {number} size 每个切片的大小
* @returns {[]}
*/
export const aoChunk = (ao: any[] | Record<string | number | symbol, any>, size: number): any[] => {
const array = typeArray(ao) ? ao : aoCleanKeyOne(ao)
const length = array.length
size = ~~Math.abs(+size)
if (length < 1 || size < 1) {
return []
} else {
let index = 0
let resIndex = 0
const result = new Array(Math.ceil(length / size))
while (index < length) {
result[resIndex++] = array.slice(index, (index += size))
}
return result
}
}