diff --git a/index.html b/index.html index f39a29523..418988885 100644 --- a/index.html +++ b/index.html @@ -236,7 +236,6 @@
_.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++) {