Splitting an array

Hi All, 

Need some help with writing a logic.

I have an integer array {1,2,3,4,5,6,7,8,9,10,11,12}.

I want an output as three arrays {1,2,3,4,5},  {6,7,8,9,10},  {11,12}

Any function or quick work around to split an array by grouping first five elements in an array, next five elements in array and so on

TIA

Arun

  Discussion posts and replies are publicly visible

Parents
  • This should do Slight smile

    Just change the local!inputArray and local!maximumPerArray for other results.

    a!localVariables(
      local!inputArray: {1,2,3,4,5,6,7,8,9,10,11,12},
      local!totalArray: length(local!inputArray),
      local!maximumPerArray: 5,
    
      local!amountArrays: ceiling(local!totalArray / local!maximumPerArray),
      local!iterationArray: enumerate(local!amountArrays),
    
      a!forEach(
        items: local!iterationArray,
        expression: with(
          local!leftAmountToCut: fv!item * local!maximumPerArray,
          local!rightAmountToCut: local!totalArray - ((fv!item + 1) * local!maximumPerArray),
          
          rdrop(
            ldrop(
              local!inputArray,
              local!leftAmountToCut
            ),
            if(local!rightAmountToCut < 0, 0, local!rightAmountToCut)
          )
        )
      )
    )

Reply
  • This should do Slight smile

    Just change the local!inputArray and local!maximumPerArray for other results.

    a!localVariables(
      local!inputArray: {1,2,3,4,5,6,7,8,9,10,11,12},
      local!totalArray: length(local!inputArray),
      local!maximumPerArray: 5,
    
      local!amountArrays: ceiling(local!totalArray / local!maximumPerArray),
      local!iterationArray: enumerate(local!amountArrays),
    
      a!forEach(
        items: local!iterationArray,
        expression: with(
          local!leftAmountToCut: fv!item * local!maximumPerArray,
          local!rightAmountToCut: local!totalArray - ((fv!item + 1) * local!maximumPerArray),
          
          rdrop(
            ldrop(
              local!inputArray,
              local!leftAmountToCut
            ),
            if(local!rightAmountToCut < 0, 0, local!rightAmountToCut)
          )
        )
      )
    )

Children
No Data