Created
March 16, 2026 21:41
-
-
Save trycf/767ae5cbd18d0da73b27878b1fc5e552 to your computer and use it in GitHub Desktop.
TryCF Gist
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <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