<?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>To find the greatest number in the array without max function</title><link>https://community.appian.com/discussions/f/rules/27017/to-find-the-greatest-number-in-the-array-without-max-function</link><description>conventional method to find the gratest number using for loop</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: To find the greatest number in the array without max function</title><link>https://community.appian.com/thread/124195?ContentTypeID=1</link><pubDate>Sun, 14 Jan 2024 14:16:56 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:0a9d7896-ca1d-4f23-bda0-b7bde5ff06cc</guid><dc:creator>Mathieu Drouin</dc:creator><description>&lt;p&gt;A couple of suggestions:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;You can simply set the batchSize to 1 in the pagingConfiguration. With this you can reduce the number of times you use the index function.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;You can&amp;nbsp;simply cast to an integer rather than getting the first element of the array, this removes another index.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;a!localVariables(
  local!list: { 67, 80, 100, 102, 150 },
  local!map: a!forEach(
    items: local!list,
    expression: a!map(number: fv!item)
  ),
  local!dataSubset: todatasubset(
    arrayToPage: local!map,
    pagingConfiguration: a!pagingInfo(
      startIndex: 1,
      batchSize: 1,
      sort: a!sortInfo(field: &amp;quot;number&amp;quot;, ascending: false)
    )
  ),
  cast(
    typeof(1),
    index(local!dataSubset.data, &amp;quot;number&amp;quot;, null)
  )
)&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: To find the greatest number in the array without max function</title><link>https://community.appian.com/thread/124191?ContentTypeID=1</link><pubDate>Sun, 14 Jan 2024 12:54:36 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:4efd0e8a-f297-4c50-bfce-423dbe5f95d7</guid><dc:creator>Harshit Bumb (Appyzie)</dc:creator><description>&lt;p&gt;sort is actually an undocumented function. This neither comes up as a suggestion nor there is any documentation page for the same.&amp;nbsp;&lt;br /&gt;I won&amp;#39;t advise using it.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: To find the greatest number in the array without max function</title><link>https://community.appian.com/thread/124187?ContentTypeID=1</link><pubDate>Sun, 14 Jan 2024 12:40:43 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:1a4f2558-7740-4c7d-82ec-21baba1d1577</guid><dc:creator>Sri Ram Kaja</dc:creator><description>&lt;p&gt;Hi &lt;a href="/members/kameshr0002"&gt;romeoraja&lt;/a&gt;&amp;nbsp;,&lt;/p&gt;
&lt;p&gt;Below one might be helpful.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;a!localVariables(
  local!list: { 67, 80, 100, 102, 150 },
  local!map: a!forEach(
    items: local!list,
    expression: a!map(number: fv!item)
  ),
  index(
    index(
      index(
        todatasubset(
          arrayToPage: local!map,
          pagingConfiguration: a!pagingInfo(
            startIndex: 1,
            batchSize: length(local!list),
            sort: a!sortInfo(field: &amp;quot;number&amp;quot;, ascending: false)
          )
        ),
        &amp;quot;data&amp;quot;,
        {}
      ),
      &amp;quot;number&amp;quot;,
      {}
    ),
    1,
    {}
  )
)&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: To find the greatest number in the array without max function</title><link>https://community.appian.com/thread/123760?ContentTypeID=1</link><pubDate>Fri, 05 Jan 2024 17:14:11 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:660316b1-5dcf-4162-abb5-8c3b5030e404</guid><dc:creator>Amaan Shekh</dc:creator><description>&lt;p&gt;I was going with a different approach with local variables and forgot to remove &lt;em&gt;a!localVariables() &lt;/em&gt;&amp;nbsp;when I moved to rule inputs&lt;span class="emoticon" data-url="https://community.appian.com/cfs-file/__key/system/emoji/1f605.svg" title="Sweat smile"&gt;&amp;#x1f605;&lt;/span&gt;.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: To find the greatest number in the array without max function</title><link>https://community.appian.com/thread/123753?ContentTypeID=1</link><pubDate>Fri, 05 Jan 2024 15:49:40 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:1abe979b-3212-440d-869b-38d6647d6dec</guid><dc:creator>Mike Schmitt</dc:creator><description>&lt;p&gt;I&amp;#39;d point out that you&amp;#39;re not actually declaring any local variable in this rule, and thus it&amp;#39;s unnecessary to even call &lt;em&gt;a!localVariables()&lt;/em&gt; other than potentially if you want to add one in the future for easier understanding.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: To find the greatest number in the array without max function</title><link>https://community.appian.com/thread/123717?ContentTypeID=1</link><pubDate>Fri, 05 Jan 2024 06:21:14 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:9063bedb-945d-44a0-a587-ce0e8a92013d</guid><dc:creator>Amaan Shekh</dc:creator><description>&lt;p&gt;&lt;span&gt;Here is an O(n) approach implemented like C, employing a temporary variable to store the current maximum (rule input ). In this implementation, a recursive approach has been utilized. If you have any questions or need further clarification, feel free to ask.&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;
  if(
    ri!currentIndex &amp;gt; length(ri!arr),
    ri!currentMax,
    rule!maxNum(
      arr: ri!arr,
      currentMax: if(
        ri!currentMax &amp;gt; ri!arr[ri!currentIndex],
        ri!currentMax,
        ri!arr[ri!currentIndex]
      ),
      currentIndex: ri!currentIndex + 1
    )
  )


/*arr: array in which we needs to find max num*/
/*currentMax: first element of array*/
/*current index: first index of array (1 in case of appian)*/&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;img style="max-height:240px;max-width:320px;" alt=" " src="/resized-image/__size/640x480/__key/communityserver-discussions-components-files/15/pastedimage1704435642759v1.png" /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;result-&amp;gt;&amp;nbsp;&lt;img style="max-height:240px;max-width:320px;" alt=" " src="/resized-image/__size/640x480/__key/communityserver-discussions-components-files/15/pastedimage1704435655991v2.png" /&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: To find the greatest number in the array without max function</title><link>https://community.appian.com/thread/123540?ContentTypeID=1</link><pubDate>Mon, 01 Jan 2024 09:18:45 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:34317bab-543e-475f-8bdb-f8fd333e42da</guid><dc:creator>kraty Maheshwari</dc:creator><description>&lt;p&gt;This might be helpful.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;a!localVariables(
  local!listOfNumber: { 67, 80, 100, 102, 150 },
  a!forEach(
    items: local!listOfNumber,
    expression: a!localVariables(
      local!item: fv!item,
      local!updatedList: remove(local!listOfNumber, fv!index),
      if(
        count(
          wherecontains(
            true,
            a!forEach(
              items: local!updatedList,
              expression: local!item &amp;gt; fv!item
            )
          )
        ) = count(local!updatedList),
        fv!item,
        {}
      )
    )
  )
)&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: To find the greatest number in the array without max function</title><link>https://community.appian.com/thread/106093?ContentTypeID=1</link><pubDate>Fri, 30 Dec 2022 10:33:45 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:30885a05-0bc2-4f15-b6b6-6438b38c53f3</guid><dc:creator>Alex Boerescu</dc:creator><description>&lt;p&gt;Or use the sort function:&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;a!localVariables(
  local!list:{5,4,7,9,2,5,0},
  sort(local!list)[length(local!list)]
)&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: To find the greatest number in the array without max function</title><link>https://community.appian.com/thread/106084?ContentTypeID=1</link><pubDate>Thu, 29 Dec 2022 12:28:18 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:3421f360-0ec8-4630-9989-3cd95bc9b30d</guid><dc:creator>prasadp</dc:creator><description>&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;reduce(
  rule!getMaxNumber(accumulator: _, item: _),
  0,
  ri!array
)&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;We can use reduce function&lt;/p&gt;
&lt;p&gt;Create a rule which will compare the current item and accumulator and return the max number and use that rule as predicate in reduce fucntion&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: To find the greatest number in the array without max function</title><link>https://community.appian.com/thread/106076?ContentTypeID=1</link><pubDate>Thu, 29 Dec 2022 08:15:44 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:7b7c5d51-9776-4711-a00f-35c927c94fcd</guid><dc:creator>romeoraja</dc:creator><description>&lt;p&gt;was practicing to do same as in c , using a local temp variable&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: To find the greatest number in the array without max function</title><link>https://community.appian.com/thread/106060?ContentTypeID=1</link><pubDate>Thu, 29 Dec 2022 06:41:25 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:fdab089b-18a1-49c8-a7c0-da6c148b7391</guid><dc:creator>Harshit Bumb (Appyzie)</dc:creator><description>&lt;p&gt;Why do you want to do it without the max() function when you can use it?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>