X-Git-Url: http://git.roojs.org/?a=blobdiff_plain;f=Array.js;h=a3b684d73e3b0d28b3aac55260f907e9de402f4d;hb=242e8cb7d4eb31741bfb8d282303ac36f54dd00e;hp=18c3aaa13c68f6c87ca7054457c7f0e7d8d07a30;hpb=4d9cd83949f3c24871af08cebb30b1f8102ac4c9;p=roojs1 diff --git a/Array.js b/Array.js index 18c3aaa13c..a3b684d73e 100644 --- a/Array.js +++ b/Array.js @@ -13,13 +13,14 @@ */ Roo.applyIf(Array.prototype, { /** + * * Checks whether or not the specified object exists in the array. * @param {Object} o The object to check for * @return {Number} The index of o in the array (or -1 if it is not found) */ indexOf : function(o){ for (var i = 0, len = this.length; i < len; i++){ - if(this[i] == o) return i; + if(this[i] == o) { return i; } } return -1; }, @@ -33,5 +34,56 @@ Roo.applyIf(Array.prototype, { if(index != -1){ this.splice(index, 1); } + }, + /** + * Map (JS 1.6 compatibility) + * @param {Function} function to call + */ + map : function(fun ) + { + var len = this.length >>> 0; + if (typeof fun != "function") { + throw new TypeError(); + } + var res = new Array(len); + var thisp = arguments[1]; + for (var i = 0; i < len; i++) + { + if (i in this) { + res[i] = fun.call(thisp, this[i], i, this); + } + } + + return res; + }, + /** + * equals + * @param {Array} o The array to compare to + * @returns {Boolean} true if the same + */ + equals : function(b) + { + // https://stackoverflow.com/questions/3115982/how-to-check-if-two-arrays-are-equal-with-javascript + if (this === b) { + return true; + } + if (b == null) { + return false; + } + if (this.length !== b.length) { + return false; + } + + // sort?? a.sort().equals(b.sort()); + + for (var i = 0; i < this.length; ++i) { + if (this[i] !== b[i]) { + return false; + } + } + return true; } -}); \ No newline at end of file +}); + + +