_.VERSION = '1.5.0';From 5e32f2223c22b3f7ae8341164688cc310a668bc2 Mon Sep 17 00:00:00 2001
From: Jeremy Ashkenas
- 1.5.0 — Jul. 6, 2013 — DiffLinks & Suggested Reading
Change Log
+ 1.5.0 — Jul. 6, 2013 — Diff
- Underscore is a + Underscore is a utility-belt library for JavaScript that provides a lot of the functional programming support that you would expect in Prototype.js @@ -368,9 +368,9 @@
The project is - hosted on GitHub. + hosted on GitHub. You can report bugs and discuss features on the - issues page, + issues page, on Freenode in the #documentcloud channel, or send tweets to @documentcloud.
@@ -397,7 +397,7 @@
- 1.5.0 — Jul. 6, 2013 — Diff
+ 1.5.0 — Jul. 6, 2013 — Diff
- 1.4.4 — Jan. 30, 2013 — Diff
+ 1.4.4 — Jan. 30, 2013 — Diff
- 1.4.3 — Dec. 4, 2012 — Diff
+ 1.4.3 — Dec. 4, 2012 — Diff
- 1.4.2 — Oct. 1, 2012 — Diff
+ 1.4.2 — Oct. 1, 2012 — Diff
- 1.4.1 — Oct. 1, 2012 — Diff
+ 1.4.1 — Oct. 1, 2012 — Diff
- 1.4.0 — Sept. 27, 2012 — Diff
+ 1.4.0 — Sept. 27, 2012 — Diff
_.zip(['moe', 'larry', 'curly'], [30, 40, 50], [true, false, false]); => [["moe", 30, true], ["larry", 40, false], ["curly", 50, false]] --
- unzip_.unzip(*arrays)
-
- The opposite of zip. Given a number of arrays, returns a
- series of new arrays, the first of which contains all of the first elements
- in the input arrays, the second of which contains all of the second elements,
- and so on. Use with apply to pass in an array of arrays.
-
-_.unzip(["moe", 30, true], ["larry", 40, false], ["curly", 50, false]); -=> [['moe', 'larry', 'curly'], [30, 40, 50], [true, false, false]] +_.zip.apply(_, arrayOfRowsOfData); +=> arrayOfColumnsOfData
diff --git a/test/arrays.js b/test/arrays.js
index f592af4e9..294086523 100644
--- a/test/arrays.js
+++ b/test/arrays.js
@@ -137,19 +137,17 @@ $(document).ready(function() {
var names = ['moe', 'larry', 'curly'], ages = [30, 40, 50], leaders = [true];
var stooges = _.zip(names, ages, leaders);
equal(String(stooges), 'moe,30,true,larry,40,,curly,50,', 'zipped together arrays of different lengths');
- });
- test('unzip', function() {
- var stoogesUnzipped = _.unzip(['moe',30, 'stooge 1'],['larry',40, 'stooge 2'],['curly',50, 'stooge 3']);
- deepEqual(stoogesUnzipped, [['moe','larry','curly'],[30,40,50], ['stooge 1', 'stooge 2', 'stooge 3']], 'unzipped pairs');
+ stooges = _.zip(['moe',30, 'stooge 1'],['larry',40, 'stooge 2'],['curly',50, 'stooge 3']);
+ deepEqual(stooges, [['moe','larry','curly'],[30,40,50], ['stooge 1', 'stooge 2', 'stooge 3']], 'zipped pairs');
// In the case of difference lengths of the tuples undefineds
// should be used as placeholder
- stoogesUnzipped = _.unzip(['moe',30],['larry',40],['curly',50, 'extra data']);
- deepEqual(stoogesUnzipped, [['moe','larry','curly'],[30,40,50], [undefined, undefined, 'extra data']], 'unzipped pairs');
+ stooges = _.zip(['moe',30],['larry',40],['curly',50, 'extra data']);
+ deepEqual(stooges, [['moe','larry','curly'],[30,40,50], [undefined, undefined, 'extra data']], 'zipped pairs with empties');
- var emptyUnzipped = _.unzip([]);
- deepEqual(emptyUnzipped, [], 'unzipped empty');
+ var empty = _.zip([]);
+ deepEqual(empty, [], 'unzipped empty');
});
test('object', function() {
diff --git a/underscore.js b/underscore.js
index a2712954f..5a9518ab5 100644
--- a/underscore.js
+++ b/underscore.js
@@ -495,15 +495,6 @@
// Zip together multiple lists into a single array -- elements that share
// an index go together.
_.zip = function() {
- return _.unzip.apply(_, slice.call(arguments));
- };
-
- // The complementary operation to `_.zip`. Passed a list of arrays, returns
- // a list of arrays, the first of which contains all of the first elements,
- // the second the second, and so on. For example, `_.unzip` given
- // `['a',1],['b',2],['c',3]` returns the array
- // `[['a','b','c'],[1,2,3]]`.
- _.unzip = function() {
var length = _.max(_.pluck(arguments, "length").concat(0));
var results = new Array(length);
for (var i = 0; i < length; i++) {
From edbf2952c2b71f81c6449aef384bdf233a0d63bc Mon Sep 17 00:00:00 2001
From: Jeremy Ashkenas underscore.js
- Underscore.js 1.5.0
+
@@ -237,7 +236,7 @@ Underscore.js 1.5.1
http://underscorejs.org
-(c) 2009-2011 Jeremy Ashkenas, DocumentCloud Inc.
-(c) 2011-2013 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
+(c) 2009-2013 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
Underscore may be freely distributed under the MIT license.Baseline setup
- _.VERSION = '1.5.0'; _.VERSION = '1.5.1';
_.zip = function() {
- return _.unzip.apply(_, slice.call(arguments));
- };The inverse operation to _.zip. If given an array of pairs it
-returns an array of the paired elements split into two left and
-right element arrays, if given an array of triples it returns a
-three element array and so on. For example, _.unzip given
-[['a',1],['b',2],['c',3]] returns the array
-[['a','b','c'],[1,2,3]].
-
_.unzip = function() {
var length = _.max(_.pluck(arguments, "length").concat(0));
var results = new Array(length);
for (var i = 0; i < length; i++) {
@@ -1238,11 +1214,11 @@ Array Functions
- Converts lists into objects. Pass either a single array of [key, value]
pairs, or two parallel arrays of the same length -- one of keys, and one of
@@ -1267,11 +1243,11 @@
If the browser doesn't supply us with indexOf (I'm looking at you, MSIE), we need this function. Return the position of the first occurrence of an @@ -1302,11 +1278,11 @@
Delegates to ECMAScript 5's native lastIndexOf if available.
Generate an integer Array containing an arithmetic progression. A port of
the native Python range() function. See
@@ -1362,11 +1338,11 @@
Reusable constructor function for prototype setting.
@@ -1403,11 +1379,11 @@Create a function bound to a given object (assigning this, and arguments,
optionally). Delegates to ECMAScript 5's native Function.bind if
@@ -1435,11 +1411,11 @@
Partially apply a function by creating a version that has had some of its
arguments pre-filled, without changing its dynamic this context.
@@ -1457,11 +1433,11 @@
Bind all of an object's methods to that object. Useful for ensuring that all callbacks defined on an object belong to it. @@ -1479,11 +1455,11 @@
Memoize an expensive function by storing its results.
@@ -1502,11 +1478,11 @@Delays a function for the given number of milliseconds, and then calls it with the arguments supplied. @@ -1522,11 +1498,11 @@
Defers a function, scheduling it to run after the current call stack has cleared. @@ -1541,11 +1517,11 @@
Returns a function, that, when invoked, will only be triggered at most once during a given window of time. Normally, the throttled function will run @@ -1562,7 +1538,7 @@
Returns a function, that, as long as it continues to be invoked, will not be triggered. The function will be called after it stops being called for @@ -1621,11 +1597,11 @@
Returns a function that will be executed at most one time, no matter how often you call it. Useful for lazy initialization. @@ -1647,11 +1623,11 @@
Returns the first function passed as an argument to the second, allowing you to adjust arguments, run code before and after, and @@ -1671,11 +1647,11 @@
Returns a function that is the composition of a list of functions, each consuming the return value of the function that follows. @@ -1697,11 +1673,11 @@
Returns a function that will only be executed after being called N times.
@@ -1719,11 +1695,11 @@Retrieve the names of an object's properties.
Delegates to ECMAScript 5's native Object.keys
@@ -1766,11 +1742,11 @@
Retrieve the values of an object's properties.
@@ -1786,11 +1762,11 @@Convert an object into a list of [key, value] pairs.
Invert the keys and values of an object. The values must be serializable.
@@ -1826,11 +1802,11 @@Return a sorted list of the function names available on the object.
Aliased as methods
@@ -1849,11 +1825,11 @@
Extend a given object with all the properties in passed-in object(s).
@@ -1874,11 +1850,11 @@Return a copy of the object only containing the whitelisted properties.
@@ -1897,11 +1873,11 @@Return a copy of the object without the blacklisted properties.
@@ -1920,11 +1896,11 @@Fill in a given object with default properties.
@@ -1945,11 +1921,11 @@Create a (shallow-cloned) duplicate of an object.
@@ -1964,11 +1940,11 @@Invokes interceptor with the obj, and then returns obj. The primary purpose of this method is to "tap into" a method chain, in @@ -1985,11 +1961,11 @@
Internal recursive comparison function for isEqual.
Identical objects are equal. 0 === -0, but they aren't identical.
See the Harmony egal proposal.
@@ -2018,11 +1994,11 @@
A strict comparison is necessary because null == undefined.
Unwrap any wrapped objects.
@@ -2051,11 +2027,11 @@Compare [[Class]] names.
Strings, numbers, dates, and booleans are compared by value.
@@ -2085,11 +2061,11 @@Primitives and their corresponding object wrappers are equivalent; thus, "5" is
equivalent to new String("5").
@@ -2103,11 +2079,11 @@
NaNs are equivalent, but non-reflexive. An egal comparison is performed for
other numeric values.
@@ -2122,11 +2098,11 @@
Coerce dates and booleans to numeric primitive values. Dates are compared by their millisecond representations. Note that invalid dates with millisecond representations @@ -2140,11 +2116,11 @@
RegExps are compared by their source patterns and flags.
@@ -2162,11 +2138,11 @@Assume equality for cyclic structures. The algorithm for detecting cyclic
structures is adapted from ES 5.1 section 15.12.3, abstract operation JO.
@@ -2180,11 +2156,11 @@
Linear search. Performance is inversely proportional to the number of unique nested structures. @@ -2198,11 +2174,11 @@
Objects with different constructors are not equivalent, but Objects
from different frames are.
@@ -2219,11 +2195,11 @@
Add the first object to the stack of traversed objects.
@@ -2237,11 +2213,11 @@Recursively compare objects and arrays.
@@ -2253,11 +2229,11 @@Compare array lengths to determine if a deep comparison is necessary.
@@ -2271,11 +2247,11 @@Deep compare the contents, ignoring non-numeric properties.
@@ -2291,11 +2267,11 @@Deep compare objects.
@@ -2308,11 +2284,11 @@Count the expected number of properties.
@@ -2324,11 +2300,11 @@Deep compare each member.
@@ -2342,11 +2318,11 @@Ensure that both objects contain the same number of properties.
@@ -2364,11 +2340,11 @@Remove the first object from the stack of traversed objects.
@@ -2383,11 +2359,11 @@Perform a deep comparison to check if two objects are equal.
@@ -2401,11 +2377,11 @@Is a given array, string, or object empty? An "empty" object has no enumerable own-properties. @@ -2423,11 +2399,11 @@
Is a given value a DOM element?
@@ -2441,11 +2417,11 @@Is a given value an array? Delegates to ECMA5's native Array.isArray @@ -2460,11 +2436,11 @@
Is a given variable an object?
@@ -2478,11 +2454,11 @@Add some isType methods: isArguments, isFunction, isString, isNumber, isDate, isRegExp.
@@ -2498,11 +2474,11 @@Define a fallback version of the method in browsers (ahem, IE), where there isn't any inspectable "Arguments" type. @@ -2519,11 +2495,11 @@
Optimize isFunction if appropriate.
Is a given object a finite number?
@@ -2557,11 +2533,11 @@Is the given value NaN? (NaN is the only number which does not equal itself).
Is a given value a boolean?
@@ -2593,11 +2569,11 @@Is a given value equal to null?
@@ -2611,11 +2587,11 @@Is a given variable undefined?
@@ -2629,11 +2605,11 @@Shortcut function for checking if an object has a given property directly on itself (in other words, not on a prototype). @@ -2648,11 +2624,11 @@
Run Underscore.js in noConflict mode, returning the _ variable to its
previous owner. Returns a reference to the Underscore object.
@@ -2693,11 +2669,11 @@
Keep the identity function around for default iterators.
@@ -2711,11 +2687,11 @@Run a function n times.
@@ -2731,11 +2707,11 @@Return a random integer between min and max (inclusive).
@@ -2753,11 +2729,11 @@List of HTML entities for escaping.
@@ -2779,11 +2755,11 @@Regexes containing the keys and values listed immediately above.
@@ -2798,11 +2774,11 @@Functions for escaping and unescaping strings to/from HTML interpolation.
@@ -2821,11 +2797,11 @@If the value of the named property is a function then invoke it with the
object as context; otherwise, return it.
@@ -2842,11 +2818,11 @@
Add your own custom functions to the Underscore object.
@@ -2867,11 +2843,11 @@Generate a unique integer id (unique within the entire client session). Useful for temporary DOM ids. @@ -2888,11 +2864,11 @@
By default, Underscore uses ERB-style template delimiters, change the following template settings to use alternative delimiters. @@ -2909,11 +2885,11 @@
When customizing templateSettings, if you don't want to define an
interpolation, evaluation or escaping regex, we need one that is
@@ -2927,11 +2903,11 @@
Certain characters need to be escaped so that they can be put into a string literal. @@ -2954,11 +2930,11 @@
JavaScript micro-templating, similar to John Resig's implementation. Underscore templating handles arbitrary delimiters, preserves whitespace, @@ -2974,11 +2950,11 @@
Combine delimiters into one regular expression via alternation.
@@ -2994,11 +2970,11 @@Compile the template source, escaping string literals appropriately.
@@ -3028,11 +3004,11 @@If a variable is not specified, place data values in local scope.
@@ -3060,11 +3036,11 @@Provide the compiled function source as a convenience for precompilation.
@@ -3079,11 +3055,11 @@Add a "chain" function, which will delegate to the wrapper.
@@ -3097,11 +3073,11 @@If Underscore is called as a function, it returns a wrapped object that can be used OO-style. This wrapper holds altered versions of all the @@ -3126,11 +3102,11 @@
Helper function to continue chaining intermediate results.
@@ -3144,11 +3120,11 @@Add all of the Underscore functions to the wrapper object.
@@ -3160,11 +3136,11 @@Add all mutator Array functions to the wrapper.
@@ -3184,11 +3160,11 @@Add all accessor Array functions to the wrapper.
@@ -3207,11 +3183,11 @@