Fixes filter in YString.
authordsc <david.schoonover@gmail.com>
Tue, 7 Dec 2010 11:48:55 +0000 (03:48 -0800)
committerdsc <david.schoonover@gmail.com>
Tue, 7 Dec 2010 11:48:55 +0000 (03:48 -0800)
src/Y/types/collection.cjs
src/Y/types/string.cjs

index b8db902..beb799e 100644 (file)
@@ -65,7 +65,7 @@ YBase.subclass('YCollection', {
         var o = this._o, acc = new o.constructor();
         for ( var name in o )
             if ( fn.call( context || this, o[name], name, o ) )
-            acc[name] = o[name];
+                acc[name] = o[name];
         return acc;
     },
     
index 1d57932..5b26886 100644 (file)
@@ -166,4 +166,15 @@ YCollection.subclass('YString', function(YString){
         return this;
     };
     
+    this['filter'] =
+    function filter(fn){
+        fn = Function.toFunction(fn);
+        for ( var out = "", s = this._o, L = s.length, cxt = arguments[1]||this, i = 0; i < L; ++i ) {
+            var c = s.charAt(i);
+            if ( fn.call(cxt, c, i, s) )
+                out += c;
+        }
+        return out;
+    };
+    
 });