From d4a5ed6a733c75c6b1813e17a5ff5063ac087db7 Mon Sep 17 00:00:00 2001 From: Jeremy Ashkenas Date: Sat, 31 Oct 2009 08:26:03 -0400 Subject: [PATCH] version 0.3.3 is on the books -- with reduceRight --- index.html | 18 +++++++++++++----- underscore-min.js | 2 +- underscore.js | 2 +- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/index.html b/index.html index 9850daf9d..a25d68a86 100644 --- a/index.html +++ b/index.html @@ -107,11 +107,11 @@

- + - +
Development Version (0.3.2)Development Version (0.3.3) 16kb, Uncompressed with Comments
Production Version (0.3.2)Production Version (0.3.3) 4kb, Packed and Gzipped
@@ -216,7 +216,9 @@ var sum = _.reduce([1, 2, 3], 0, function(memo, num){ return memo + num }); Alias: foldr
The right-associative version of reduce. Delegates to the - JavaScript 1.8 version of reduceRight, if it exists. + JavaScript 1.8 version of reduceRight, if it exists. Foldr + is not as useful in JavaScript as it would be in a language with lazy + evaluation.

 var list = [[0, 1], [2, 3], [4, 5]];
@@ -229,8 +231,8 @@ var flat = _.reduceRight(list, [], function(a, b) { return a.concat(b); });
         
Looks through each value in the list, returning the first one that passes a truth test (iterator). The function returns as - soon as it finds the first acceptable element, and doesn't continue to - traverse the list. + soon as it finds an acceptable element, and doesn't traverse the + entire list.

 var even = _.detect([1, 2, 3, 4, 5, 6], function(num){ return num % 2 == 0; });
@@ -767,6 +769,12 @@ _.template(list, {people : ['moe', 'curly', 'larry']});
 
       

Change Log

+

+ 0.3.3
+ Added the JavaScript 1.8 function reduceRight. Aliased it + as foldr, and aliased reduce as foldl. +

+

0.3.2
Now runs on stock Rhino diff --git a/underscore-min.js b/underscore-min.js index ee3af5177..ec7f39785 100644 --- a/underscore-min.js +++ b/underscore-min.js @@ -1 +1 @@ -(function(){var a=this;var c=a._;var b=a._={};if(typeof exports!=="undefined"){b=exports}b.VERSION="0.3.2";b.each=function(n,k,j){var f=0;try{if(n.forEach){n.forEach(k,j)}else{if(n.length){for(var h=0,d=n.length;h=d.computed&&(d={value:m,computed:j})});return d.value};b.min=function(g,f,e){if(!f&&b.isArray(g)){return Math.min.apply(Math,g)}var d={computed:Infinity};b.each(g,function(m,h,k){var j=f?f.call(e,m,h,k):m;jg?1:0}),"value")};b.sortedIndex=function(j,h,f){f=f||b.identity;var d=0,g=j.length;while(d>1;f(j[e])=0})})};b.zip=function(){var d=b.toArray(arguments);var g=b.max(b.pluck(d,"length"));var f=new Array(g);for(var e=0;e=0;e--){arguments=[d[e].apply(this,arguments)]}return arguments[0]}};b.keys=function(d){return b.map(d,function(f,e){return e})};b.values=function(d){return b.map(d,b.identity)};b.extend=function(d,f){for(var e in f){d[e]=f[e]}return d};b.clone=function(d){return b.extend({},d)};b.isEqual=function(e,d){if(e===d){return true}var h=typeof(e),k=typeof(d);if(h!=k){return false}if(e==d){return true}if(e.isEqual){return e.isEqual(d)}if(h!=="object"){return false}var f=b.keys(e),j=b.keys(d);if(f.length!=j.length){return false}for(var g in e){if(!b.isEqual(e[g],d[g])){return false}}return true};b.isElement=function(d){return !!(d&&d.nodeType==1)};b.isArray=function(d){return Object.prototype.toString.call(d)=="[object Array]"};b.isFunction=function(d){return Object.prototype.toString.call(d)=="[object Function]"};b.isUndefined=function(d){return typeof d=="undefined"};b.noConflict=function(){a._=c;return this};b.identity=function(d){return d};b.uniqueId=function(d){var e=this._idCounter=(this._idCounter||0)+1;return d?d+e:e};b.template=function(f,e){var d=new Function("obj","var p=[],print=function(){p.push.apply(p,arguments);};with(obj){p.push('"+f.replace(/[\r\t\n]/g," ").split("<%").join("\t").replace(/((^|%>)[^\t]*)'/g,"$1\r").replace(/\t=(.*?)%>/g,"',$1,'").split("\t").join("');").split("%>").join("p.push('").split("\r").join("\\'")+"');}return p.join('');");return e?d(e):d};b.forEach=b.each;b.inject=b.reduce;b.filter=b.select;b.every=b.all;b.some=b.any})(); \ No newline at end of file +(function(){var a=this;var c=a._;var b=a._={};if(typeof exports!=="undefined"){b=exports}b.VERSION="0.3.3";b.each=function(n,k,j){var f=0;try{if(n.forEach){n.forEach(k,j)}else{if(n.length){for(var h=0,d=n.length;h=d.computed&&(d={value:m,computed:j})});return d.value};b.min=function(g,f,e){if(!f&&b.isArray(g)){return Math.min.apply(Math,g)}var d={computed:Infinity};b.each(g,function(m,h,k){var j=f?f.call(e,m,h,k):m;jg?1:0}),"value")};b.sortedIndex=function(j,h,f){f=f||b.identity;var d=0,g=j.length;while(d>1;f(j[e])=0})})};b.zip=function(){var d=b.toArray(arguments);var g=b.max(b.pluck(d,"length"));var f=new Array(g);for(var e=0;e=0;e--){arguments=[d[e].apply(this,arguments)]}return arguments[0]}};b.keys=function(d){return b.map(d,function(f,e){return e})};b.values=function(d){return b.map(d,b.identity)};b.extend=function(d,f){for(var e in f){d[e]=f[e]}return d};b.clone=function(d){if(b.isArray(d)){return d.slice(0)}return b.extend({},d)};b.isEqual=function(e,d){if(e===d){return true}var h=typeof(e),k=typeof(d);if(h!=k){return false}if(e==d){return true}if(e.isEqual){return e.isEqual(d)}if(h!=="object"){return false}var f=b.keys(e),j=b.keys(d);if(f.length!=j.length){return false}for(var g in e){if(!b.isEqual(e[g],d[g])){return false}}return true};b.isElement=function(d){return !!(d&&d.nodeType==1)};b.isArray=function(d){return Object.prototype.toString.call(d)=="[object Array]"};b.isFunction=function(d){return Object.prototype.toString.call(d)=="[object Function]"};b.isUndefined=function(d){return typeof d=="undefined"};b.noConflict=function(){a._=c;return this};b.identity=function(d){return d};b.uniqueId=function(d){var e=this._idCounter=(this._idCounter||0)+1;return d?d+e:e};b.template=function(f,e){var d=new Function("obj","var p=[],print=function(){p.push.apply(p,arguments);};with(obj){p.push('"+f.replace(/[\r\t\n]/g," ").split("<%").join("\t").replace(/((^|%>)[^\t]*)'/g,"$1\r").replace(/\t=(.*?)%>/g,"',$1,'").split("\t").join("');").split("%>").join("p.push('").split("\r").join("\\'")+"');}return p.join('');");return e?d(e):d};b.forEach=b.each;b.foldl=b.inject=b.reduce;b.foldr=b.reduceRight;b.filter=b.select;b.every=b.all;b.some=b.any})(); \ No newline at end of file diff --git a/underscore.js b/underscore.js index 9b2dfb84b..e198f6a4b 100644 --- a/underscore.js +++ b/underscore.js @@ -23,7 +23,7 @@ if (typeof exports !== 'undefined') _ = exports; // Current version. - _.VERSION = '0.3.2'; + _.VERSION = '0.3.3'; /*------------------------ Collection Functions: ---------------------------*/