wm003
4 Mar 2008, 3:27 AM
//Sorts an Array that consists of date-objects only (Ext-specific)
Array.prototype.sortDates = function() {
return this.sort(function(a,b){
return parseInt(a.format("YmdHis"))-parseInt(b.format("YmdHis"));
});
};
The following was found at http://www.4umi.com/web/javascript/array.htm
(There are some more useful prototypes ...)
//override the existing indexOf to be able to look after a specific index and check vartypes
//extended with begin and strict attributes (backward compatible to current ext-indexOf function!)
Array.prototype.indexOf = function( o, b, s ) {
for( var i = +b || 0, len = this.length; i < len; i++) {
//check for objecttype to make this function work with date-objects also
if( this[i]===o || s && this[i]==o || Ext.isDate(o) && this[i].toString()==o.toString()) {
return i;
}
}
return -1;
};
// Array.unique( strict ) - Remove duplicate values
//based on new indexOf defined above
Array.prototype.unique = function(b) {
var a = [], i, len = this.length;
for(i=0; i<len; i++ ) {
if( a.indexOf( this[i], 0, b ) < 0 ) {
a.push( this[i] );
}
}
return a;
};
Array.prototype.sortDates = function() {
return this.sort(function(a,b){
return parseInt(a.format("YmdHis"))-parseInt(b.format("YmdHis"));
});
};
The following was found at http://www.4umi.com/web/javascript/array.htm
(There are some more useful prototypes ...)
//override the existing indexOf to be able to look after a specific index and check vartypes
//extended with begin and strict attributes (backward compatible to current ext-indexOf function!)
Array.prototype.indexOf = function( o, b, s ) {
for( var i = +b || 0, len = this.length; i < len; i++) {
//check for objecttype to make this function work with date-objects also
if( this[i]===o || s && this[i]==o || Ext.isDate(o) && this[i].toString()==o.toString()) {
return i;
}
}
return -1;
};
// Array.unique( strict ) - Remove duplicate values
//based on new indexOf defined above
Array.prototype.unique = function(b) {
var a = [], i, len = this.length;
for(i=0; i<len; i++ ) {
if( a.indexOf( this[i], 0, b ) < 0 ) {
a.push( this[i] );
}
}
return a;
};