Created
August 13, 2024 04:24
-
-
Save aliboy08/30c5f3459f937662f58e3e1fd716b4e9 to your computer and use it in GitHub Desktop.
Batch items
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function batch_items(items, items_per_batch){ | |
let batched_items = []; | |
let group_items = []; | |
let group_index = 0; | |
for( let i = 0; i < items.length; i++ ) { | |
group_index++; | |
group_items.push(items[i]); | |
if( group_index == items_per_batch || i == items.length-1 ) { | |
// new group / reset | |
batched_items.push(group_items); | |
group_items = []; | |
group_index = 0; | |
} | |
} | |
return batched_items | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment