Skip to content

Instantly share code, notes, and snippets.

View yanarp's full-sized avatar
👑
yanarpy yanarp

Narp yanarp

👑
yanarpy yanarp
  • Apex
View GitHub Profile
@yanarp
yanarp / Split Array in Equal Batch
Created July 4, 2022 14:50
Fnc to split array in numbered batches
function splitPayload(arr, batchSize) {
let tempArr = arr;
let result = [];
let rest = arr.length % batchSize; // number of non divisble elements
let partLength = Math.floor(tempArr.length / batchSize); // number to divide remaining number of array element
let restData = tempArr.splice(0, rest)
result.push(restData)
for (let i = 0; i < partLength; i++) {
let restData = arr.splice(0, batchSize)
result.push(restData);