Question
You have an array and you want to seperate by a batch of 3
/*
You have an array and you want to seperate by a batch of 3
E.g
Array: {"a", "b", "c", "d", "e", "f", "g", "h"}
Expected output: { ["a", "b", "c"], [ "d", "e", "f"], ["g", "h"] }
*/
a!localVariables(
local!chunkSize: 3,
local!startingList: { "a", "b", "c", "d", "e", "f", "g", "h" },
local!wholeListSize: length(local!startingList),
local!numChunks: ceiling(local!wholeListSize / local!chunkSize),
local!data: a!forEach(
enumerate(local!numChunks),
a!localVariables(
local!currentStartIndex: fv!item * local!chunkSize + 1,
/* note: this utilizes zero-index of fv!item */
local!currentIndices: enumerate(local!chunkSize) + local!currentStartIndex,
/* this rule just unions the input array with itself and rejects null values */
reject(
fn!isnull,
index(
local!startingList,
local!currentIndices,
null()
)
)
)
),
local!data
)