Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save trycf/59ba8dc1863919e45d991522c82e5636 to your computer and use it in GitHub Desktop.

Select an option

Save trycf/59ba8dc1863919e45d991522c82e5636 to your computer and use it in GitHub Desktop.
TryCF Gist
<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