Skip to content

Instantly share code, notes, and snippets.

@jbuda
Last active December 15, 2015 22:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbuda/5336134 to your computer and use it in GitHub Desktop.
Save jbuda/5336134 to your computer and use it in GitHub Desktop.
ColdFusion block to output the intersection of two arrays
<cfscript>
colourArray = ["Red","Orange","Yellow","Green","Blue","Indigo","Violet"];
colourArrayTwo = ["Yellow","Green","Red","Violet"];
presentInBoth = [];
// loop initial array with values
for(i=1;i<=arrayLen(colourArray);i++) {
// loop over inner array
for(j=1;j<=arrayLen(colourArrayTwo);j++) {
// compare the values of the outer array and the inner array and append value to resulting array
if (colourArray[i] == colourArrayTwo[j])
presentInBoth.arrayAppend(presentInBoth,colourArray[i]);
}
}
writedump(presentInBoth);
</cfscript>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment