Hi guys,
I am facing a trouble that I have a list of numbers:
List of Number (Integer) - 6 items
I need to split them to three array, and each array has 2 number values.
so it still going to be a list, which has 3 array, and each array has 2 values.
Can anyone can help me for this?
Discussion posts and replies are publicly visible
This code snippet is an example for splitting an array into sub-arrays (for now, embedded in a dictionary) where you can set the desired "chunk" size (the length of the resulting sub-lists) by changing the value of local!neListChunkSize.
a!localVariables( local!list: {11, 22, 33, 44, 55, 66}, local!newListChunkSize: 2, local!newListLength: tointeger(ceiling(length(local!list) / local!newListChunkSize)), a!forEach( enumerate(local!newListLength), { chunk: fv!item, subList: { local!list[fv!index + fv!item], local!list[fv!index + fv!item + 1] } } ) )
Try this example, where local!array is your initial list of integers, and local!childArrayLength is your desired size for the nested arrays:
a!localVariables( local!array: {10,20,30,40,50,60,70,80,90,100}, local!childArrayLength: 2, local!finalSize: ceiling(count(local!array)/local!childArrayLength), a!forEach( items: 1+enumerate(local!finalSize), expression: { reject( fn!isnull, index( local!array, if(fv!isFirst,fv!item,fv!item*local!childArrayLength-local!childArrayLength+1)+enumerate(local!childArrayLength), null ) ) } ) )
great minds think alike, i guess ;-)
Mike,
Actually I have already adapted a solution which you post in another question form.
It is working perfertly, thanks!
This is also works! thanks Chris
Was going to say! ;)