g2601_2700.s2677_chunk_array.solution.ts Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of leetcode-in-kotlin Show documentation
Show all versions of leetcode-in-kotlin Show documentation
Kotlin-based LeetCode algorithm problem solutions, regularly updated
// #Easy #2023_07_27_Time_55_ms_(96.89%)_Space_45.2_MB_(71.69%)
function chunk(arr: any[], size: number): any[][] {
if (arr.length === 0) return []
if (size >= arr.length) return [arr]
let i: number = 0
let res: Array> = []
while (i < arr.length) {
res.push(arr.slice(i, i + size))
i += size
}
return res
}
export { chunk }