Created
February 25, 2026 08:07
-
-
Save trycf/59ba8dc1863919e45d991522c82e5636 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 array = ['a','b','c','a']; | |
| var mystruct = {}; | |
| var arraynew = []; | |
| var len = arrayLen(array); | |
| for (var i = 1; i <= len; i++) { | |
| for (var j = i + 1; j <= len; j++) { | |
| // 1. Grab your two words | |
| var val1 = array[i]; | |
| var val2 = array[j]; | |
| // 2. Put them in a temp array and sort them alphabetically | |
| // This ensures ['dog', 'bear'] ALWAYS becomes ['bear', 'dog'] | |
| var tempPair = [val1, val2]; | |
| arraySort(tempPair, "textnocase"); | |
| // 3. Create a unique string key (e.g., "bear|dog") | |
| var pairKey = tempPair; | |
| writeDump(pairKey); | |
| // 4. Check if we've seen this combo before | |
| if (!structKeyExists(mystruct, pairKey)) { | |
| // Add the original pair to our result | |
| arrayAppend(arraynew, [val1, val2]); | |
| // Mark this combo as "seen" in our tracker | |
| mystruct[pairKey] = true; | |
| } | |
| } | |
| } | |
| </cfscript> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment