I am facing issue with a piece of code, with slight modification I am getting different results which should not be the case.
Version 1 is giving the correct results, I am facing issue with Version 2 which is the actual code.
Version 1:
<cfset keywords = listToArray("1,2,3,4,5,6,7,8,9,10")>
<!--- Common Code Below --->
<cfoutput>#getMetadata(keywords).getName()#</cfoutput>
<cfset toBeAdded = keywords>
<cfset toBeInactivated = listToArray("1,3,4,6,8")>
<cfset toBeActivated = toBeInactivated>
<cfset toBeAdded.removeAll(toBeInactivated)>
<cfset toBeInactivated.removeAll(keywords)>
<cfset toBeActivated.retainAll(keywords)>
Version 2:
<cfset keywords = []>
<cfloop from="1" to="10" index="counter">
<cfset arrayAppend( keywords, counter )>
</cfloop>
<!--- If I add following line here then it is working as expected and similar to version 1: --->
<!--- <cfset keywords = listToArray(arrayToList(keywords))> --->
<!--- Common Code Below --->
<cfoutput>#getMetadata(keywords).getName()#</cfoutput>
<cfset toBeAdded = keywords>
<cfset toBeInactivated = listToArray("1,3,4,6,8")>
<cfset toBeActivated = toBeInactivated>
<cfset toBeAdded.removeAll(toBeInactivated)>
<cfset toBeInactivated.removeAll(keywords)>
<cfset toBeActivated.retainAll(keywords)>
Outputs:
Here are the gists: Version 1
and Version 2
.
Any suggestions are greatly appreciated!
arrayAppend( keywords, JavaCast("String", counter)
. – Galatea