Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save trycf/767ae5cbd18d0da73b27878b1fc5e552 to your computer and use it in GitHub Desktop.

Select an option

Save trycf/767ae5cbd18d0da73b27878b1fc5e552 to your computer and use it in GitHub Desktop.
TryCF Gist
<cfscript>
var result = mergeListDistinct("a|b", "b|c", "|");
writedump(result);
</cfscript>
<cffunction name="mergeListDistinct" returntype="string" access="public">
<cfargument name="lList" type="string" required="true" />
<cfargument name="lListToAppend" type="string" required="true" />
<cfargument name="cDelimiter" type="string" required="false" default="," />
<cfif listLen(arguments.lListToAppend) EQ 0>
<cfreturn arguments.lList />
</cfif>
<cfif listLen(arguments.lList) EQ 0>
<cfreturn arguments.lListToAppend />
</cfif>
<cfreturn getDistinctList(lList=arguments.lList & arguments.cDelimiter & arguments.lListToAppend) />
</cffunction>
<cffunction name="getDistinctList" returntype="string" access="public">
<cfargument name="lList" type="string" required="true" />
<cfargument name="cDelimiter" type="string" required="false" default="," />
<cfreturn arrayToList(getDistinctArray(aValues=listToArray(arguments.lList, arguments.cDelimiter)), arguments.cDelimiter) />
</cffunction>
<cffunction name="getDistinctArray" returntype="array" access="public">
<cfargument name="aValues" type="array" required="true" />
<cfset var sVars = structNew() />
<cfset sVars.oHashSet = createObject("java", "java.util.LinkedHashSet") />
<cfset sVars.oHashSet.init(arguments.aValues) />
<cfreturn sVars.oHashSet.toArray() />
</cffunction>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment