Changeset 12819

Show
Ignore:
Timestamp:
03/02/08 20:21:52 (10 months ago)
Author:
elazutkin
Message:

dojox.lang.functional: adding missing everyRev() and someRev()
to facilitate conditional reversed loop. !strict

Location:
dojox/trunk/lang
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • dojox/trunk/lang/functional/reversed.js

    r11764 r12819  
    4747                        for(var i = n - 1, j = 0; i >= 0; t[j++] = f.call(o, a[i], i, a), --i); 
    4848                        return t;       // Array 
     49                }, 
     50                everyRev: function(/*Array|String*/ a, /*Function|String|Array*/ f, /*Object?*/ o){ 
     51                        // summary: tests whether all elements in the array pass the test  
     52                        //      implemented by the provided function. 
     53                        if(typeof a == "string"){ a = a.split(""); } 
     54                        o = o || d.global; f = df.lambda(f); 
     55                        for(var i = a.length - 1; i >= 0; --i){ 
     56                                if(!f.call(o, a[i], i, a)){ 
     57                                        return false;   // Boolean 
     58                                } 
     59                        } 
     60                        return true;    // Boolean 
     61                }, 
     62                someRev: function(/*Array|String*/ a, /*Function|String|Array*/ f, /*Object?*/ o){ 
     63                        // summary: tests whether some element in the array passes the test  
     64                        //      implemented by the provided function. 
     65                        if(typeof a == "string"){ a = a.split(""); } 
     66                        o = o || d.global; f = df.lambda(f); 
     67                        for(var i = a.length - 1; i >= 0; --i){ 
     68                                if(f.call(o, a[i], i, a)){ 
     69                                        return true;    // Boolean 
     70                                } 
     71                        } 
     72                        return false;   // Boolean 
    4973                } 
    5074        }); 
  • dojox/trunk/lang/tests/array.js

    r11764 r12819  
    5656                        t.assertTrue(df.every(iter, isOdd)); 
    5757                }, 
     58                function testEveryRev1(t){ t.assertFalse(df.everyRev([1, 2, 3], isOdd)); }, 
     59                function testEveryRev2(t){ t.assertTrue(df.everyRev([1, 3, 5], isOdd)); }, 
    5860 
    5961                function testSome1(t){ t.assertFalse(df.some([2, 4, 6], isOdd)); }, 
     
    6365                        t.assertTrue(df.some(iter, isOdd)); 
    6466                }, 
     67                function testSomeRev1(t){ t.assertFalse(df.someRev([2, 4, 6], isOdd)); }, 
     68                function testSomeRev2(t){ t.assertTrue(df.someRev([1, 2, 3], isOdd)); }, 
    6569 
    6670                function testReduce1(t){ t.assertEqual(df.reduce([4, 2, 1], "x-y"), 1); },