From c5ea3c1e37a9a6b44a10590a9928877d58480e71 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Tue, 17 Feb 2009 01:16:17 -0700 Subject: [PATCH] without() doesn't handle array input; need diff() Yet again, without() is completely worthless by itself. And for some reason, the prototypejs people continue to insist that it is better than diff(). Even though it isn't. --- imp/js/src/DimpBase.js | 2 +- imp/js/src/DimpCore.js | 17 ++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/imp/js/src/DimpBase.js b/imp/js/src/DimpBase.js index cb4b19351..424e3c715 100644 --- a/imp/js/src/DimpBase.js +++ b/imp/js/src/DimpBase.js @@ -909,7 +909,7 @@ var DimpBase = { _expirePPCache: function(ids) { - this.ppfifo = this.ppfifo.without(ids); + this.ppfifo = this.ppfifo.diff(ids); ids.each(function(i) { delete this.ppcache[i]; }, this); diff --git a/imp/js/src/DimpCore.js b/imp/js/src/DimpCore.js index b76d3d935..863cdad06 100644 --- a/imp/js/src/DimpCore.js +++ b/imp/js/src/DimpCore.js @@ -576,15 +576,18 @@ Element.addMethods({ /* Create some utility functions. */ Object.extend(Array.prototype, { + // Need our own diff() function because prototypejs's without() function + // does not handle array input. + diff: function(values) + { + return this.select(function(value) { + return !values.include(value); + }); + }, numericSort: function() { - return this.collect(Number).sort(function(a, b) { - if (a > b) { - return 1; - } else if (a < b) { - return -1; - } - return 0; + return this.collect(Number).sort(function(a,b) { + return (a > b) ? 1 : ((a < b) ? -1 : 0); }); } }); -- 2.11.0