<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.appian.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Question on converting array into sub-arrays</title><link>https://community.appian.com/discussions/f/rules/8185/question-on-converting-array-into-sub-arrays</link><description>Given an array {&amp;quot;a&amp;quot;,&amp;quot;b&amp;quot;,&amp;quot;c&amp;quot;,&amp;quot;d&amp;quot;,&amp;quot;e&amp;quot;,&amp;quot;f&amp;quot;, &amp;quot;g&amp;quot;,&amp;quot;h&amp;quot;,&amp;quot;i&amp;quot;} Is there a way to convert it to an equal size sub-arrays as follows (say by specifying 3 in this case): {{&amp;quot;a&amp;quot;,&amp;quot;b&amp;quot;,&amp;quot;c&amp;quot;}, {&amp;quot;d&amp;quot;,&amp;quot;e&amp;quot;,&amp;quot;f&amp;quot;}, {&amp;quot;g&amp;quot;,&amp;quot;h&amp;quot;,&amp;quot;i&amp;quot;}} 
 OriginalPostID-227719 
 OriginalPostID-22771</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: Question on converting array into sub-arrays</title><link>https://community.appian.com/thread/65087?ContentTypeID=1</link><pubDate>Thu, 07 Mar 2019 15:49:20 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:24d8baec-9ad4-4383-a387-539e2e6e75dc</guid><dc:creator>Gregor Gisler-Merz</dc:creator><description>Use the following code snippet. Just add a arbitrary array and define the split size. Comes in extremely handy if you have massive data to tackle and want to save memory.&lt;br /&gt;
&lt;br /&gt;
load(&lt;br /&gt;
  local!loops: tointeger(length(ri!Ids)/10)+1,&lt;br /&gt;
  local!indexIndicator: (enumerate(local!loops)+1)*10,&lt;br /&gt;
  &lt;br /&gt;
  a!forEach(&lt;br /&gt;
  local!indexIndicator,&lt;br /&gt;
  with(&lt;br /&gt;
    local!lowerIndex:fv!item-10,&lt;br /&gt;
    local!upperIndex:fv!item,&lt;br /&gt;
    a!forEach(ri!Ids,&lt;br /&gt;
      if(and(fv!index&amp;gt;local!lowerIndex,fv!index&amp;lt;=local!upperIndex),&lt;br /&gt;
      fv!item,&lt;br /&gt;
      {})&lt;br /&gt;
    )&lt;br /&gt;
  )&lt;br /&gt;
  )&lt;br /&gt;
)&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Question on converting array into sub-arrays</title><link>https://community.appian.com/thread/34365?ContentTypeID=1</link><pubDate>Tue, 09 Aug 2016 22:48:29 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:596f5105-db48-4719-a550-c2e1a4a12472</guid><dc:creator>Chris</dc:creator><description>Great!&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Question on converting array into sub-arrays</title><link>https://community.appian.com/thread/34364?ContentTypeID=1</link><pubDate>Tue, 09 Aug 2016 22:47:06 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:05c6d9c8-9ace-4755-865a-afb326c3c445</guid><dc:creator>mohamedb</dc:creator><description>Thank you Chris very much. The rules are working fine.&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Question on converting array into sub-arrays</title><link>https://community.appian.com/thread/34363?ContentTypeID=1</link><pubDate>Tue, 09 Aug 2016 22:25:09 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:938948f9-7a8c-4f2c-96bc-1061bbe79204</guid><dc:creator>Chris</dc:creator><description>I&amp;#39;ll attach an export of the rules, if you would like to try importing them straight to your environment.  We are on Appian 16.1.&lt;br /&gt;&lt;p&gt;&lt;a href="/cfs-filesystemfile/__key/communityserver-discussions-components-files/15/Chris_5F00_Test-_2D00_-Patch.zip"&gt;Chris_Test - Patch.zip&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Question on converting array into sub-arrays</title><link>https://community.appian.com/thread/34360?ContentTypeID=1</link><pubDate>Tue, 09 Aug 2016 22:12:38 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:e2195876-4a3a-4955-b7e2-72aaee700349</guid><dc:creator>mohamedb</dc:creator><description>I still an empty list ...&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a href="/cfs-filesystemfile/__key/communityserver-discussions-components-files/15/output.PNG"&gt;&lt;img src="/cfs-filesystemfile/__key/communityserver-discussions-components-files/15/output.PNG" alt=" " /&gt;&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Question on converting array into sub-arrays</title><link>https://community.appian.com/thread/34358?ContentTypeID=1</link><pubDate>Tue, 09 Aug 2016 21:48:43 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:8e4333d8-04a5-4de7-a91c-f09a760ba4fc</guid><dc:creator>Chris</dc:creator><description>Sorry for a few typos, few notes:&lt;br /&gt;&lt;br /&gt;rule!chris_pivotGetIndex_helper(num, separation, count)&lt;br /&gt;&lt;br /&gt;should be:&lt;br /&gt;&lt;br /&gt;rule!chris_pivotGetIndex_helper(num, separation, index)&lt;br /&gt;&lt;br /&gt;rule!chris_pivotGetItems(array,index)&lt;br /&gt;&lt;br /&gt;should be:&lt;br /&gt;&lt;br /&gt;rule!chris_pivotGetItems(array,indexes)&lt;br /&gt;&lt;br /&gt;Ensure in the last one above, array is multiple and indexes is not (single valued string).  If the rest of the parameter types match from my initial post, you should be seeing data..&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Question on converting array into sub-arrays</title><link>https://community.appian.com/thread/34356?ContentTypeID=1</link><pubDate>Tue, 09 Aug 2016 20:54:32 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:20479265-cf68-4275-9d7e-35d90c1003ad</guid><dc:creator>mohamedb</dc:creator><description>@Appian: Drawing the Grid above is a straight forward nested loops in java. It is also a very common scenario. Is there an easy way to do the same in Appian?&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Question on converting array into sub-arrays</title><link>https://community.appian.com/thread/34355?ContentTypeID=1</link><pubDate>Tue, 09 Aug 2016 20:50:10 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:03a7bc1e-1d71-4cda-8b75-1c20a20f0008</guid><dc:creator>mohamedb</dc:creator><description>The parameters for each rule do not match the variables used in the rule. When I updated them to avoid an error, I got an empty array as a result.&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Question on converting array into sub-arrays</title><link>https://community.appian.com/thread/34353?ContentTypeID=1</link><pubDate>Tue, 09 Aug 2016 19:31:52 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:72a4ce87-6045-4a56-b858-97625ee8bd8c</guid><dc:creator>Chris</dc:creator><description>Hi mohamedb, the rules output the desired format in my environment - what results are you seeing?&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Question on converting array into sub-arrays</title><link>https://community.appian.com/thread/34329?ContentTypeID=1</link><pubDate>Tue, 09 Aug 2016 02:12:06 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:9dc35d79-ca6d-4678-a36f-e294ec6413b1</guid><dc:creator>mohamedb</dc:creator><description>@csteward: Thanks for sharing. I have tried to test the rules shared but they didnot render the expected {a,d,g},{b,e,h},{c,f,i} output. I am thinking of another approach too. But, if we can get your solution to work it will be more dynamic. Hope that it worked when you tried it.&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Question on converting array into sub-arrays</title><link>https://community.appian.com/thread/34318?ContentTypeID=1</link><pubDate>Mon, 08 Aug 2016 22:31:40 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:df3737d0-dd0d-41c2-9f8a-2c19d21b6430</guid><dc:creator>Chris</dc:creator><description>To achieve the grid you want, you will be looking for arrays in this format instead, so each can be used as a column:  {a,d,g},{b,e,h},{c,f,i}.  This function below will handle a dynamic sized list and column count and perform a type of pivoting for you, returning an array of arrays in the desired format which you should be able to iterate through and generate your columns, give it a try:&lt;br /&gt;&lt;br /&gt;rule!chris_pivot()&lt;br /&gt;&lt;br /&gt;with(&lt;br /&gt;  local!array: {&amp;quot;a&amp;quot;,&amp;quot;b&amp;quot;,&amp;quot;c&amp;quot;,&amp;quot;d&amp;quot;,&amp;quot;e&amp;quot;,&amp;quot;f&amp;quot;,&amp;quot;g&amp;quot;,&amp;quot;h&amp;quot;,&amp;quot;i&amp;quot;},&lt;br /&gt;  local!columns: 3,&lt;br /&gt;  local!count: count(local!array),&lt;br /&gt;  local!indexes: apply(rule!chris_pivotGetIndex(separation: local!columns, num: _, count: _),&lt;br /&gt;    merge(&lt;br /&gt;      1+enumerate(local!columns),&lt;br /&gt;      apply(rule!chris_pivotGetSizes(max: local!count, size: local!columns, start: _), 1+enumerate(local!columns))&lt;br /&gt;    )&lt;br /&gt;  ),&lt;br /&gt;  local!newArrays: apply(rule!chris_pivotGetItems(array: local!array, indexes: _),local!indexes),&lt;br /&gt;  &lt;br /&gt;  local!newArrays&lt;br /&gt;)&lt;br /&gt;&lt;br /&gt;Helper Rules:&lt;br /&gt;&lt;br /&gt;rule!chris_pivotGetIndex(num, separation, count) - inputs single valued integers:&lt;br /&gt;&lt;br /&gt;joinarray(&lt;br /&gt;  apply(rule!chris_pivotGetIndex_helper(num: ri!num, separation: ri!separation, index: _), enumerate(ri!count))&lt;br /&gt;  ,&amp;quot;,&amp;quot;&lt;br /&gt;)&lt;br /&gt;&lt;br /&gt;rule!chris_pivotGetIndex_helper(num, separation, count) - inputs single valued integers:&lt;br /&gt;&lt;br /&gt;(ri!index * ri!separation) + ri!num&lt;br /&gt;&lt;br /&gt;rule!chris_pivotGetSizes(max, start, size) - inputs single valued integers:&lt;br /&gt;&lt;br /&gt;ceiling((ri!max+1-ri!start)/ri!size)&lt;br /&gt;&lt;br /&gt;rule!chris_pivotGetItems(array,index) - both inputs text, &amp;#39;array&amp;#39; is multiple:&lt;br /&gt;&lt;br /&gt;index(ri!array,apply(fn!tointeger,split(ri!indexes,&amp;quot;,&amp;quot;)),null)&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Question on converting array into sub-arrays</title><link>https://community.appian.com/thread/34287?ContentTypeID=1</link><pubDate>Sat, 06 Aug 2016 08:03:14 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:0526984a-bae8-478b-a45f-19d4a421055f</guid><dc:creator>mohamedb</dc:creator><description>*Construct grid from main array&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Question on converting array into sub-arrays</title><link>https://community.appian.com/thread/34286?ContentTypeID=1</link><pubDate>Sat, 06 Aug 2016 05:45:15 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:2f615b4b-e33d-4b16-af92-c4c56118cc71</guid><dc:creator>mohamedb</dc:creator><description>It will be a bit tricky constructing the sub-arrays from the main array using OOTB functions.&lt;br /&gt;&lt;br /&gt;My goal is to construct the following grid from the main grid:&lt;br /&gt;---------------------------------&lt;br /&gt;column1  |  column2  |  column3 |&lt;br /&gt;---------------------------------&lt;br /&gt;a        |b          |c         |&lt;br /&gt;---------------------------------&lt;br /&gt;d        |e          |f         |&lt;br /&gt;---------------------------------&lt;br /&gt;g        |h          |i         |&lt;br /&gt;---------------------------------&lt;br /&gt;&lt;br /&gt;Any good ideas how to acheive that?&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Question on converting array into sub-arrays</title><link>https://community.appian.com/thread/34281?ContentTypeID=1</link><pubDate>Sat, 06 Aug 2016 01:00:04 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:71ddf08d-e199-4277-89aa-300a5ebc3ab8</guid><dc:creator>Michael Nye</dc:creator><description>I don&amp;#39;t believe there&amp;#39;s an existing function for this. You would have to use a combination of looping functions: &lt;a href="https://forum.appian.com/suite/help/16.2/Looping_Functions.html#any.28.29"&gt;forum.appian.com/.../Looping_Functions.html&lt;/a&gt; and array functions:&lt;br /&gt;&lt;a href="https://forum.appian.com/suite/help/16.2/Array_Functions.html"&gt;forum.appian.com/.../Array_Functions.html&lt;/a&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>