<?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>Could you optimize the below code?: (String anagrams)</title><link>https://community.appian.com/discussions/f/general/17890/could-you-optimize-the-below-code-string-anagrams</link><description>load( local!str1: &amp;quot;abca&amp;quot;, local!str2: &amp;quot;ABAC&amp;quot;, local!splitstr1: apply( fn!index( lower(local!str1), _, &amp;quot;&amp;quot; ), enumerate( len( local!str1 ) ) + 1 ), local!splitstr2: apply( fn!index( lower(local!str2), _, &amp;quot;&amp;quot; ), enumerate( len( local!str2 ) ) + 1 ), local</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: Could you optimize the below code?: (String anagrams)</title><link>https://community.appian.com/thread/70459?ContentTypeID=1</link><pubDate>Wed, 13 Nov 2019 13:23:23 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:1048355b-855a-4753-98bb-25e37a68ee49</guid><dc:creator>Stefan Helzle</dc:creator><description>&lt;p&gt;sort() is internal API and should not be used. Sorry ... With a bit of trickery you can use todatasubset() to sort your array of characters.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Could you optimize the below code?: (String anagrams)</title><link>https://community.appian.com/thread/70456?ContentTypeID=1</link><pubDate>Wed, 13 Nov 2019 13:15:25 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:63de121a-2ed9-457a-aeac-d8fa8d4f3f84</guid><dc:creator>abhishek manjunath</dc:creator><description>&lt;p&gt;Check this out:&lt;/p&gt;
&lt;p&gt;load(&lt;br /&gt; local!str1: &amp;quot;dabca&amp;quot;,&lt;br /&gt; local!str2: &amp;quot;abAcD&amp;quot;,&lt;br /&gt; if(&lt;br /&gt; or(sort(code(lower(local!str1)))-sort(code(lower(local!str2)))),&amp;quot;Not Anagram&amp;quot;,&amp;quot;Anagram&amp;quot;&lt;br /&gt; )&lt;br /&gt;)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Could you optimize the below code?: (String anagrams)</title><link>https://community.appian.com/thread/70453?ContentTypeID=1</link><pubDate>Wed, 13 Nov 2019 12:59:05 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:bcd0f6fb-9d31-4229-b4b6-9015e01f98a5</guid><dc:creator>viveku3486</dc:creator><description>&lt;p&gt;Thanks for correcting the solution Ankita, I wasn&amp;#39;t aware about Anagram functionality and my assumption was its just the character match that is required.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Could you optimize the below code?: (String anagrams)</title><link>https://community.appian.com/thread/70403?ContentTypeID=1</link><pubDate>Tue, 12 Nov 2019 05:12:22 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:82573244-5b9a-4a6e-b515-eee621b15cac</guid><dc:creator>ankitab0001</dc:creator><description>&lt;p&gt;I&amp;nbsp;believe, for an anagram, the letters should not only match but appear exactly the same number of times in both the words in different order. Check this out.:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;load(
  local!str1: &amp;quot;abca&amp;quot;,
  local!str2: &amp;quot;abA&amp;quot;,
  
  local!unicode1:code(lower(local!str1)),
  local!uniqueUnicode1: union(local!unicode1,local!unicode1),
local!unicode2:code(lower(local!str2)),
local!uniqueUnicode2:union(local!unicode2,local!unicode2),

local!str1Details:

a!forEach(local!uniqueUnicode1, 
{character:fv!item,times:count(wherecontains(fv!item,local!unicode1))}),

local!str2Details:a!forEach(local!uniqueUnicode2, 
{character:fv!item,times:count(wherecontains(fv!item,local!unicode2))}),

local!isMatch:a!forEach(local!str1Details,
    
  fv!item.times = index(local!str2Details.times, wherecontains(fv!item.character,local!str2Details.character),{})
     
  ),
  if(contains(toboolean(local!isMatch),false()),&amp;quot;Not an anagram&amp;quot;,&amp;quot;anagram&amp;quot;)
)&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Could you optimize the below code?: (String anagrams)</title><link>https://community.appian.com/thread/70397?ContentTypeID=1</link><pubDate>Mon, 11 Nov 2019 14:40:19 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:2f159e84-0880-4188-8e5c-5479e36cd407</guid><dc:creator>viveku3486</dc:creator><description>&lt;p&gt;How about this?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;load(&lt;br /&gt; local!str1: &amp;quot;abca&amp;quot;,&lt;br /&gt; local!str2: &amp;quot;ABAC&amp;quot;,&lt;br /&gt; &lt;br /&gt; local!unicode1:code(lower(local!str1)),&lt;br /&gt; local!unicode2:code(lower(local!str2)),&lt;/p&gt;
&lt;p&gt;&lt;br /&gt; if(&lt;br /&gt; contains(local!unicode1,local!unicode2),&lt;br /&gt; &amp;quot;Anagram&amp;quot;,&lt;br /&gt; &amp;quot;Naah!!&amp;quot;&lt;br /&gt; )&lt;br /&gt;)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Could you optimize the below code?: (String anagrams)</title><link>https://community.appian.com/thread/70394?ContentTypeID=1</link><pubDate>Mon, 11 Nov 2019 13:42:56 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:6f5e7852-c97e-45ef-9a8b-287400aa1b78</guid><dc:creator>Krishna Chaitanya Mallavarapu</dc:creator><description>&lt;p&gt;load(&lt;br /&gt; local!str1: &amp;quot;abca&amp;quot;,&lt;br /&gt; local!str2: &amp;quot;ABAC&amp;quot;,&lt;br /&gt; local!arrayList: a!forEach(&lt;br /&gt; items: {&lt;br /&gt; local!str1,&lt;br /&gt; local!str2&lt;br /&gt; },&lt;br /&gt; expression: apply(&lt;br /&gt; fn!index(&lt;br /&gt; lower(&lt;br /&gt; fv!item&lt;br /&gt; ),&lt;br /&gt; _,&lt;br /&gt; &amp;quot;&amp;quot;&lt;br /&gt; ),&lt;br /&gt; enumerate(&lt;br /&gt; len(&lt;br /&gt; fv!item&lt;br /&gt; )&lt;br /&gt; ) + 1&lt;br /&gt; )&lt;br /&gt; ),&lt;br /&gt; if(&lt;br /&gt; length(&lt;br /&gt; intersection(&lt;br /&gt; local!arrayList[1],&lt;br /&gt; local!arrayList[2]&lt;br /&gt; )&lt;br /&gt; ) = 0,&lt;br /&gt; &amp;quot;Anagram&amp;quot;,&lt;br /&gt; &amp;quot;Naah!&amp;quot;&lt;br /&gt; )&lt;br /&gt;)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>