without() doesn't handle array input; need diff()
authorMichael M Slusarz <slusarz@curecanti.org>
Tue, 17 Feb 2009 08:16:17 +0000 (01:16 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Wed, 18 Feb 2009 06:01:52 +0000 (23:01 -0700)
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
imp/js/src/DimpCore.js

index cb4b193..424e3c7 100644 (file)
@@ -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);
index b76d3d9..863cdad 100644 (file)
@@ -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);
         });
     }
 });