mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-03 16:47:49 +00:00
Add _.unzip. [closes #225]
Former-commit-id: 4b2c7fc068fd430f3d78de850a5f7670fd0e1a4e
This commit is contained in:
@@ -118,6 +118,7 @@
|
||||
'union',
|
||||
'uniq',
|
||||
'unique',
|
||||
'unzip',
|
||||
'without',
|
||||
'zip',
|
||||
'zipObject'
|
||||
@@ -296,8 +297,8 @@
|
||||
'without'
|
||||
];
|
||||
|
||||
/** List of methods used by Underscore */
|
||||
var underscoreMethods = _.without.apply(_, [allMethods].concat([
|
||||
/** List of Lo-Dash only methods */
|
||||
var lodashOnlyMethods = [
|
||||
'at',
|
||||
'bindKey',
|
||||
'cloneDeep',
|
||||
@@ -310,8 +311,12 @@
|
||||
'merge',
|
||||
'parseInt',
|
||||
'partialRight',
|
||||
'runInContext'
|
||||
]));
|
||||
'runInContext',
|
||||
'unzip'
|
||||
];
|
||||
|
||||
/** List of methods used by Underscore */
|
||||
var underscoreMethods = _.without.apply(_, [allMethods].concat(lodashOnlyMethods));
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
@@ -970,22 +975,7 @@
|
||||
vm.runInContext(data.source, context);
|
||||
var lodash = context._;
|
||||
|
||||
_.each([
|
||||
'assign',
|
||||
'at',
|
||||
'bindKey',
|
||||
'createCallback',
|
||||
'findIndex',
|
||||
'findKey',
|
||||
'forIn',
|
||||
'forOwn',
|
||||
'isPlainObject',
|
||||
'merge',
|
||||
'parseInt',
|
||||
'partialRight',
|
||||
'runInContext',
|
||||
'zipObject'
|
||||
], function(methodName) {
|
||||
_.each(lodashOnlyMethods.concat('assign'), function(methodName) {
|
||||
equal(lodash[methodName], undefined, '_.' + methodName + ' should not exist: ' + basename);
|
||||
});
|
||||
|
||||
|
||||
52
test/test.js
52
test/test.js
@@ -2787,6 +2787,58 @@
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
QUnit.module('lodash.unzip');
|
||||
|
||||
(function() {
|
||||
var object = {
|
||||
'an empty array': [
|
||||
[],
|
||||
[]
|
||||
],
|
||||
'0-tuples': [
|
||||
[[], []],
|
||||
[]
|
||||
],
|
||||
'1-tuples': [
|
||||
[['moe'], ['larry']],
|
||||
[['moe', 'larry']]
|
||||
],
|
||||
'2-tuples': [
|
||||
[['moe', 30], ['larry', 40]],
|
||||
[['moe', 'larry'], [30, 40]]
|
||||
],
|
||||
'3-tuples': [
|
||||
[['moe', 30, true], ['larry', 40, false]],
|
||||
[['moe', 'larry'], [30, 40], [true, false]]
|
||||
]
|
||||
};
|
||||
|
||||
_.forOwn(object, function(pair, key) {
|
||||
test('should work with ' + key, function() {
|
||||
var actual = _.unzip(pair[0]);
|
||||
deepEqual(actual, pair[1]);
|
||||
deepEqual(_.zip.apply(_, actual), pair[1].length ? pair[0] : pair[1]);
|
||||
});
|
||||
});
|
||||
|
||||
test('should work with tuples of different lengths', function() {
|
||||
var pair = [
|
||||
[['moe', 30], ['larry', 40, false]],
|
||||
[['moe', 'larry'], [30, 40], [undefined, false]]
|
||||
];
|
||||
|
||||
var actual = _.unzip(pair[0]);
|
||||
ok(1 in actual);
|
||||
deepEqual(actual, pair[1]);
|
||||
|
||||
actual = _.zip.apply(_, actual);
|
||||
ok(2 in actual[0]);
|
||||
deepEqual(actual, [['moe', 30, undefined], ['larry', 40, false]]);
|
||||
});
|
||||
}());
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
QUnit.module('lodash.where');
|
||||
|
||||
(function() {
|
||||
|
||||
Reference in New Issue
Block a user