Actionscript:
-
function uniqueCompare(arr:Array, compare:Function):void {
-
var leng:int = arr.length;
-
for (var i:int = 0; i<leng; i++){
-
for (var j:int = i + 1; j<leng; j++){
-
compare(arr[i], arr[j]);
-
}
-
}
-
}
-
-
var numbers:Array = [1, 2, 3, 4, 5];
-
-
uniqueCompare(numbers, compareCallback);
-
-
function compareCallback(a:*, b:*):void {
-
trace("compare " + a + " to " + b);
-
}
-
-
/*
-
outputs:
-
compare 1 to 2
-
compare 1 to 3
-
compare 1 to 4
-
compare 1 to 5
-
compare 2 to 3
-
compare 2 to 4
-
compare 2 to 5
-
compare 3 to 4
-
compare 3 to 5
-
compare 4 to 5
-
*/
This snippet shows a function called uniqueCompare() that compares all elements in an array to all other elements in an array without repeating a comparison.