Monday, May 20, 2024

ColdFusion: List of common elements between two lists

 A udf for obtaining common list elements courtesy of  https://www.isummation.com/blog/list-common-and-list-compare-in-coldfusion/


<cffunction name="listCommon" output="false" returnType="string">
	<cfargument name="list1" type="string" required="true" />
	<cfargument name="list2" type="string" required="true" />

	<cfset var list1Array = ListToArray(arguments.List1) />
	<cfset var list2Array = ListToArray(arguments.List2) />

	<cfset list1Array.retainAll(list2Array) />

	<!— Return in list format —>
	<cfreturn ArrayToList(list1Array) />
</cffunction>