Für einen “Test” musste ich 2 unsortierte Arrays vergleichen können. Daher habe ich diese kleine Erweiterung zu prototype’s Array-Object geschrieben.
Object.extend(Array.prototype, {
compare : function() {
var arr = $A(arguments[0]);
if(this.length != arr.length) return false;
var contain = false;
for(i = 0; i < this.length; i++) {
for(y = 0; y < arr.length; y++) {
if(this[i] == arr[y]) {
contain = true;
break;
}
}
if(!contain) {
return false;
} else {
contain = false;
}
}
return true;
}
});
Ihr könnt damit Inhalte von Arrays vergleichen:
[1,2,3,4].compare([4,3,2,1]) // => true [1,2,3,4].compare([3,2,1]) // => false [1,2,3,4].compare([1,2,3,4]) // => true

