KieSun / all-of-frontend

你想知道的前端内容都在这

Home Page:https://yuchengkai.cn/docs/frontend

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

```js

katenewbie opened this issue · comments

function chunk(input, size) {
    size = Math.max(toInteger(size), 0)
    if (!Array.isArray(input)) {
        return []
    }
    if (size < 1) {
        return []
    }
    const n = input.length
    const result = []
    let start = 0
    while (start < n) {
        result.push(input.slice(start, start + size))
        start += size
    }
    return result
}

可以参考lodash源码

Originally posted by @yancongwen in #8 (comment)

在问题下回复 #8