Spaces:
Sleeping
Sleeping
Download src/lib/VRMAnimation/utils/arrayChunk.ts from ratalai/chatvrm_for_desh: direct link, hf CLI and curl.
- Browser
- Download file 512 Bytes
-
https://huggingface.co/spaces/ratalai/chatvrm_for_desh/resolve/main/src/lib/VRMAnimation/utils/arrayChunk.ts
- Command line
-
hf download hf://spaces/ratalai/chatvrm_for_desh/src/lib/VRMAnimation/utils/arrayChunk.ts
-
curl -L -o arrayChunk.ts https://huggingface.co/spaces/ratalai/chatvrm_for_desh/resolve/main/src/lib/VRMAnimation/utils/arrayChunk.ts
512 Bytes
| /** | |
| * ```js | |
| * arrayChunk( [ 1, 2, 3, 4, 5, 6 ], 2 ) | |
| * // will be | |
| * [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] | |
| * ``` | |
| */ | |
| export function arrayChunk<T>(array: ArrayLike<T>, every: number): T[][] { | |
| const N = array.length; | |
| const ret: T[][] = []; | |
| let current: T[] = []; | |
| let remaining = 0; | |
| for (let i = 0; i < N; i ++) { | |
| const el = array[i]; | |
| if (remaining <= 0) { | |
| remaining = every; | |
| current = []; | |
| ret.push(current); | |
| } | |
| current.push(el); | |
| remaining--; | |
| } | |
| return ret; | |
| } | |