
Added by roScripts on August-25-2007, 2:51 pm
// --------------------------------
// ARRAY COMPARE - V. 2
// Compare two arrays and insert
// the result (biggest array,
// elements of arrays) in a function
//
// Author: Davide Beltrame (Broly)
// Mail: info@brolyweb.com
//
// Thanks to Sephiroth (http://www.sephiroth.it) for the idea
// of the new usage of the array
// properties in the result
// --------------------------------
Array.prototype.compare = function () {
var diff, second, c, result, arrel1, arrel2;
second = arguments[0];
diff = this.length-second.length>0 ? this
: this.length-second.length != 0 ? second : "Arrays are equals";
second = diff == this ? second : this;
diff.arrel1 = new Array();
for (c=0; c<diff.length; c++) {
diff.arrel1.push("Element"+(c+1)+" of Array1 = "+diff[c])
diff.arrel1.push("Type of element"+(c+1)
+" of Array1 = "+typeof (diff[c]))
}
diff.arrel2 = new Array();
for (c=0; c<second.length; c++) {
diff.arrel2.push( second[c] );
diff.arrel2.push( typeof(second[c]));
}
result = new Array();
result.biggest = diff;
result.biggest.length = diff.length;
result.biggest.elements = diff.arrel1;
result.second = second;
result.second.length = second.length;
result.second.elements = diff.arrel2;
return result;
}
// Usage samples
arrayA = new Array("A", "B", "C", "D", "E", "F");
arrayB = new Array(1, 2, 3, 4, 5, 6, 7);
// Trace a properties
trace ("Biggest array: " + arrayA.compare(arrayB).biggest);
trace ("Second array: " + arrayA.compare(arrayB).second);
trace ("Type of 1st second Array element: "
+ arrayA.compare(arrayB).second.elements[1]);
trace("")
// Assign a properties to a var
a = arrayA.compare(arrayB).second.length;
trace("A value: " + a)
// Usage instructions
//
// Syntax:
// 1st Array to compare.compare(2nd Array to compare)
// (example: ArrayA.compare(ArrayB)
//
// New syntax for return the properties in this version
//
// The syntax is:result.(array).(property)
// For example: result.biggest.length return the
// lenght of biggest array
// result.second.lentgh return the lenght of other array
//
// Array parameter can have one of this values
//
// biggest <- the biggest array
// second <- other array
//
// PROPERTIES
//
// length <- length of the array
// elements <- list of elements and their type
// (you can return only an element or his type
// with this syntax: result.(array).elements[n]
// For example
// result.biggest.elements[0]
<- return the 1st biggest array element
// result.biggest.elements[1]
<- return the type of 1st biggest array element
// Using result.(array).elements,
Flash return a list of all elements (and their type) in the array
Added by roScripts on March-26-2008, 5:14 pm
Added by roScripts on March-26-2008, 5:13 pm
Added by roScripts on March-26-2008, 5:09 pm
Added by roScripts on March-26-2008, 5:08 pm
Added by roScripts on March-26-2008, 5:07 pm