Last active
December 15, 2015 22:50
-
-
Save jbuda/5336134 to your computer and use it in GitHub Desktop.
ColdFusion block to output the intersection of two arrays
This file contains 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> | |
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