// -------------------------------- // ARRAY COMPARE - V. 2 // Compare two arrays and insert // the result (biggest array, // elements of arrays) in a function // // Author: Davide Beltrame (Broly) // Mail: [email protected] // // 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
//1) compare arrays
var lookup = {};
for (var j in day3Arr) {
lookup[day3Arr[j]] = day3Arr[j];
}
// check
for (var i in result3) {
if (typeof lookup[result3[i]] == "undefined") {// if it's undefined, it's new
alert('NEW! ' + result3[i] + ' is new');
}// end if
}// end for