123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- if(!dojo._hasResource["dojox.lang.functional.array"]){
- dojo._hasResource["dojox.lang.functional.array"] = true;
- dojo.provide("dojox.lang.functional.array");
- dojo.require("dojox.lang.functional.lambda");
- (function(){
- var d = dojo, df = dojox.lang.functional, empty = {};
- d.mixin(df, {
-
-
- filter: function(/*Array|String|Object*/ a, /*Function|String|Array*/ f, /*Object?*/ o){
-
-
- if(typeof a == "string"){ a = a.split(""); }
- o = o || d.global; f = df.lambda(f);
- var t = [], v, i, n;
- if(d.isArray(a)){
-
- for(i = 0, n = a.length; i < n; ++i){
- v = a[i];
- if(f.call(o, v, i, a)){ t.push(v); }
- }
- }else if(typeof a.hasNext == "function" && typeof a.next == "function"){
-
- for(i = 0; a.hasNext();){
- v = a.next();
- if(f.call(o, v, i++, a)){ t.push(v); }
- }
- }else{
-
- for(i in a){
- if(!(i in empty)){
- v = a[i];
- if(f.call(o, v, i, a)){ t.push(v); }
- }
- }
- }
- return t;
- },
- forEach: function(/*Array|String|Object*/ a, /*Function|String|Array*/ f, /*Object?*/ o){
-
- if(typeof a == "string"){ a = a.split(""); }
- o = o || d.global; f = df.lambda(f);
- var i, n;
- if(d.isArray(a)){
-
- for(i = 0, n = a.length; i < n; f.call(o, a[i], i, a), ++i);
- }else if(typeof a.hasNext == "function" && typeof a.next == "function"){
-
- for(i = 0; a.hasNext(); f.call(o, a.next(), i++, a));
- }else{
-
- for(i in a){
- if(!(i in empty)){
- f.call(o, a[i], i, a);
- }
- }
- }
- return o;
- },
- map: function(/*Array|String|Object*/ a, /*Function|String|Array*/ f, /*Object?*/ o){
-
-
- if(typeof a == "string"){ a = a.split(""); }
- o = o || d.global; f = df.lambda(f);
- var t, n, i;
- if(d.isArray(a)){
-
- t = new Array(n = a.length);
- for(i = 0; i < n; t[i] = f.call(o, a[i], i, a), ++i);
- }else if(typeof a.hasNext == "function" && typeof a.next == "function"){
-
- t = [];
- for(i = 0; a.hasNext(); t.push(f.call(o, a.next(), i++, a)));
- }else{
-
- t = [];
- for(i in a){
- if(!(i in empty)){
- t.push(f.call(o, a[i], i, a));
- }
- }
- }
- return t;
- },
- every: function(/*Array|String|Object*/ a, /*Function|String|Array*/ f, /*Object?*/ o){
-
-
- if(typeof a == "string"){ a = a.split(""); }
- o = o || d.global; f = df.lambda(f);
- var i, n;
- if(d.isArray(a)){
-
- for(i = 0, n = a.length; i < n; ++i){
- if(!f.call(o, a[i], i, a)){
- return false;
- }
- }
- }else if(typeof a.hasNext == "function" && typeof a.next == "function"){
-
- for(i = 0; a.hasNext();){
- if(!f.call(o, a.next(), i++, a)){
- return false;
- }
- }
- }else{
-
- for(i in a){
- if(!(i in empty)){
- if(!f.call(o, a[i], i, a)){
- return false;
- }
- }
- }
- }
- return true;
- },
- some: function(/*Array|String|Object*/ a, /*Function|String|Array*/ f, /*Object?*/ o){
-
-
- if(typeof a == "string"){ a = a.split(""); }
- o = o || d.global; f = df.lambda(f);
- var i, n;
- if(d.isArray(a)){
-
- for(i = 0, n = a.length; i < n; ++i){
- if(f.call(o, a[i], i, a)){
- return true;
- }
- }
- }else if(typeof a.hasNext == "function" && typeof a.next == "function"){
-
- for(i = 0; a.hasNext();){
- if(f.call(o, a.next(), i++, a)){
- return true;
- }
- }
- }else{
-
- for(i in a){
- if(!(i in empty)){
- if(f.call(o, a[i], i, a)){
- return true;
- }
- }
- }
- }
- return false;
- }
- });
- })();
- }
|