root / trunk / web / dojo / dojox / lang / functional / reversed.js @ 12
History | View | Annotate | Download (1.37 KB)
| 1 |
/*
|
|---|---|
| 2 |
Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
|
| 3 |
Available via Academic Free License >= 2.1 OR the modified BSD license.
|
| 4 |
see: http://dojotoolkit.org/license for details
|
| 5 |
*/
|
| 6 |
|
| 7 |
|
| 8 |
if(!dojo._hasResource["dojox.lang.functional.reversed"]){ |
| 9 |
dojo._hasResource["dojox.lang.functional.reversed"]=true; |
| 10 |
dojo.provide("dojox.lang.functional.reversed");
|
| 11 |
dojo.require("dojox.lang.functional.lambda");
|
| 12 |
(function(){
|
| 13 |
var d=dojo,df=dojox.lang.functional;
|
| 14 |
d.mixin(df,{filterRev:function(a,f,o){
|
| 15 |
if(typeof a=="string"){ |
| 16 |
a=a.split("");
|
| 17 |
} |
| 18 |
o=o||d.global; |
| 19 |
f=df.lambda(f); |
| 20 |
var t=[],v,i=a.length-1; |
| 21 |
for(;i>=0;--i){ |
| 22 |
v=a[i]; |
| 23 |
if(f.call(o,v,i,a)){
|
| 24 |
t.push(v); |
| 25 |
} |
| 26 |
} |
| 27 |
return t;
|
| 28 |
},forEachRev:function(a,f,o){ |
| 29 |
if(typeof a=="string"){ |
| 30 |
a=a.split("");
|
| 31 |
} |
| 32 |
o=o||d.global; |
| 33 |
f=df.lambda(f); |
| 34 |
for(var i=a.length-1;i>=0;f.call(o,a[i],i,a),--i){ |
| 35 |
} |
| 36 |
},mapRev:function(a,f,o){ |
| 37 |
if(typeof a=="string"){ |
| 38 |
a=a.split("");
|
| 39 |
} |
| 40 |
o=o||d.global; |
| 41 |
f=df.lambda(f); |
| 42 |
var n=a.length,t=new Array(n),i=n-1,j=0; |
| 43 |
for(;i>=0;t[j++]=f.call(o,a[i],i,a),--i){ |
| 44 |
} |
| 45 |
return t;
|
| 46 |
},everyRev:function(a,f,o){ |
| 47 |
if(typeof a=="string"){ |
| 48 |
a=a.split("");
|
| 49 |
} |
| 50 |
o=o||d.global; |
| 51 |
f=df.lambda(f); |
| 52 |
for(var i=a.length-1;i>=0;--i){ |
| 53 |
if(!f.call(o,a[i],i,a)){
|
| 54 |
return false; |
| 55 |
} |
| 56 |
} |
| 57 |
return true; |
| 58 |
},someRev:function(a,f,o){ |
| 59 |
if(typeof a=="string"){ |
| 60 |
a=a.split("");
|
| 61 |
} |
| 62 |
o=o||d.global; |
| 63 |
f=df.lambda(f); |
| 64 |
for(var i=a.length-1;i>=0;--i){ |
| 65 |
if(f.call(o,a[i],i,a)){
|
| 66 |
return true; |
| 67 |
} |
| 68 |
} |
| 69 |
return false; |
| 70 |
}}); |
| 71 |
})(); |
| 72 |
} |