diff options
| author | Tristan Zur <tzur@web.web.ccwn.org> | 2014-03-27 22:27:47 +0100 |
|---|---|---|
| committer | Tristan Zur <tzur@web.web.ccwn.org> | 2014-03-27 22:27:47 +0100 |
| commit | b62676ca5d3d6f6ba3f019ea3f99722e165a98d8 (patch) | |
| tree | 86722cb80f07d4569f90088eeaea2fc2f6e2ef94 /js/dojo-1.6/dojox/lang/functional/reversed.js | |
Diffstat (limited to 'js/dojo-1.6/dojox/lang/functional/reversed.js')
| -rw-r--r-- | js/dojo-1.6/dojox/lang/functional/reversed.js | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/js/dojo-1.6/dojox/lang/functional/reversed.js b/js/dojo-1.6/dojox/lang/functional/reversed.js new file mode 100644 index 0000000..4ad8ea8 --- /dev/null +++ b/js/dojo-1.6/dojox/lang/functional/reversed.js @@ -0,0 +1,86 @@ +/*
+ Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved.
+ Available via Academic Free License >= 2.1 OR the modified BSD license.
+ see: http://dojotoolkit.org/license for details
+*/
+
+
+if(!dojo._hasResource["dojox.lang.functional.reversed"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
+dojo._hasResource["dojox.lang.functional.reversed"] = true;
+dojo.provide("dojox.lang.functional.reversed");
+
+dojo.require("dojox.lang.functional.lambda");
+
+// This module adds high-level functions and related constructs:
+// - reversed versions of array-processing functions similar to standard JS functions
+
+// Notes:
+// - this module provides reversed versions of standard array-processing functions:
+// forEachRev, mapRev, filterRev
+
+// Defined methods:
+// - take any valid lambda argument as the functional argument
+// - operate on dense arrays
+// - take a string as the array argument
+
+(function(){
+ var d = dojo, df = dojox.lang.functional;
+
+ d.mixin(df, {
+ // JS 1.6 standard array functions, which can take a lambda as a parameter.
+ // Consider using dojo._base.array functions, if you don't need the lambda support.
+ filterRev: function(/*Array|String*/ a, /*Function|String|Array*/ f, /*Object?*/ o){
+ // summary: creates a new array with all elements that pass the test
+ // implemented by the provided function.
+ if(typeof a == "string"){ a = a.split(""); }
+ o = o || d.global; f = df.lambda(f);
+ var t = [], v, i = a.length - 1;
+ for(; i >= 0; --i){
+ v = a[i];
+ if(f.call(o, v, i, a)){ t.push(v); }
+ }
+ return t; // Array
+ },
+ forEachRev: function(/*Array|String*/ a, /*Function|String|Array*/ f, /*Object?*/ o){
+ // summary: executes a provided function once per array element.
+ if(typeof a == "string"){ a = a.split(""); }
+ o = o || d.global; f = df.lambda(f);
+ for(var i = a.length - 1; i >= 0; f.call(o, a[i], i, a), --i);
+ },
+ mapRev: function(/*Array|String*/ a, /*Function|String|Array*/ f, /*Object?*/ o){
+ // summary: creates a new array with the results of calling
+ // a provided function on every element in this array.
+ if(typeof a == "string"){ a = a.split(""); }
+ o = o || d.global; f = df.lambda(f);
+ var n = a.length, t = new Array(n), i = n - 1, j = 0;
+ for(; i >= 0; t[j++] = f.call(o, a[i], i, a), --i);
+ return t; // Array
+ },
+ everyRev: function(/*Array|String*/ a, /*Function|String|Array*/ f, /*Object?*/ o){
+ // summary: tests whether all elements in the array pass the test
+ // implemented by the provided function.
+ if(typeof a == "string"){ a = a.split(""); }
+ o = o || d.global; f = df.lambda(f);
+ for(var i = a.length - 1; i >= 0; --i){
+ if(!f.call(o, a[i], i, a)){
+ return false; // Boolean
+ }
+ }
+ return true; // Boolean
+ },
+ someRev: function(/*Array|String*/ a, /*Function|String|Array*/ f, /*Object?*/ o){
+ // summary: tests whether some element in the array passes the test
+ // implemented by the provided function.
+ if(typeof a == "string"){ a = a.split(""); }
+ o = o || d.global; f = df.lambda(f);
+ for(var i = a.length - 1; i >= 0; --i){
+ if(f.call(o, a[i], i, a)){
+ return true; // Boolean
+ }
+ }
+ return false; // Boolean
+ }
+ });
+})();
+
+}
|
