mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-01 15:57:48 +00:00
Make _.unzip and alias of _.zip.
Former-commit-id: fca00001ad850c250f9883572c4dce7b41dde88d
This commit is contained in:
@@ -67,7 +67,8 @@
|
||||
'select': 'filter',
|
||||
'tail': 'rest',
|
||||
'take': 'first',
|
||||
'unique': 'uniq'
|
||||
'unique': 'uniq',
|
||||
'unzip': 'zip'
|
||||
};
|
||||
|
||||
/** Used to associate real names with their aliases */
|
||||
@@ -86,6 +87,7 @@
|
||||
'rest': ['drop', 'tail'],
|
||||
'some': ['any'],
|
||||
'uniq': ['unique'],
|
||||
'zip': ['unzip'],
|
||||
'zipObject': ['object']
|
||||
};
|
||||
|
||||
@@ -107,7 +109,6 @@
|
||||
'sortedIndex',
|
||||
'union',
|
||||
'uniq',
|
||||
'unzip',
|
||||
'without',
|
||||
'zip',
|
||||
'zipObject'
|
||||
@@ -284,8 +285,7 @@
|
||||
'parseInt',
|
||||
'partialRight',
|
||||
'runInContext',
|
||||
'transform',
|
||||
'unzip'
|
||||
'transform'
|
||||
];
|
||||
|
||||
/** List of all functions */
|
||||
@@ -999,9 +999,6 @@
|
||||
function Foo() {}
|
||||
Foo.prototype = { 'a': 1 };
|
||||
|
||||
actual = lodash.defaults({ 'a': null }, { 'a': 1 });
|
||||
strictEqual(actual.a, 1, '_.defaults should overwrite `null` values: ' + basename);
|
||||
|
||||
deepEqual(lodash.defaults({}, new Foo), Foo.prototype, '_.defaults should assign inherited `source` properties: ' + basename);
|
||||
deepEqual(lodash.extend({}, new Foo), Foo.prototype, '_.extend should assign inherited `source` properties: ' + basename);
|
||||
|
||||
@@ -1065,7 +1062,6 @@
|
||||
actual = lodash.pick(object, function(value) { return value != 3; });
|
||||
deepEqual(_.keys(actual), [], '_.pick should not accept a `callback`: ' + basename);
|
||||
|
||||
strictEqual(lodash.result(), null, '_.result should return `null` for falsey `object` arguments: ' + basename);
|
||||
strictEqual(lodash.some([false, true, false]), true, '_.some: ' + basename);
|
||||
deepEqual(lodash.times(null, function() {}), [null], '_.times should not coerce `n` to a number: ' + basename);
|
||||
equal(lodash.template('${a}', object), '${a}', '_.template should ignore ES6 delimiters: ' + basename);
|
||||
@@ -1581,8 +1577,7 @@
|
||||
'uniq',
|
||||
'uniqueId',
|
||||
'value',
|
||||
'where',
|
||||
'zip'
|
||||
'where'
|
||||
];
|
||||
|
||||
function strip(value) {
|
||||
@@ -1599,9 +1594,6 @@
|
||||
if (funcName == 'createCallback') {
|
||||
command += ',where';
|
||||
}
|
||||
if (funcName == 'zip') {
|
||||
command += ',unzip';
|
||||
}
|
||||
if (funcName != 'chain' && _.contains(categoryMap.Chaining.concat('mixin'), funcName)) {
|
||||
command += ',chain';
|
||||
}
|
||||
|
||||
105
test/test.js
105
test/test.js
@@ -3368,58 +3368,6 @@
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
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() {
|
||||
@@ -3486,6 +3434,59 @@
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
QUnit.module('lodash.zip');
|
||||
|
||||
(function() {
|
||||
var object = {
|
||||
'an empty array': [
|
||||
[],
|
||||
[]
|
||||
],
|
||||
'0-tuples': [
|
||||
[[], []],
|
||||
[]
|
||||
],
|
||||
'2-tuples': [
|
||||
[['moe', 'larry'], [30, 40]],
|
||||
[['moe', 30], ['larry', 40]]
|
||||
],
|
||||
'3-tuples': [
|
||||
[['moe', 'larry'], [30, 40], [true, false]],
|
||||
[['moe', 30, true], ['larry', 40, false]]
|
||||
]
|
||||
};
|
||||
|
||||
_.forOwn(object, function(pair, key) {
|
||||
test('should work with ' + key, function() {
|
||||
var actual = _.zip.apply(_, pair[0]);
|
||||
deepEqual(actual, pair[1]);
|
||||
deepEqual(_.zip.apply(_, actual), actual.length ? pair[0] : []);
|
||||
});
|
||||
});
|
||||
|
||||
test('should work with tuples of different lengths', function() {
|
||||
var pair = [
|
||||
[['moe', 30], ['larry', 40, false]],
|
||||
[['moe', 'larry'], [30, 40], [undefined, false]]
|
||||
];
|
||||
|
||||
var actual = _.zip(pair[0]);
|
||||
ok(0 in actual[2]);
|
||||
deepEqual(actual, pair[1]);
|
||||
|
||||
actual = _.zip.apply(_, actual);
|
||||
ok(2 in actual[0]);
|
||||
deepEqual(actual, [['moe', 30, undefined], ['larry', 40, false]]);
|
||||
});
|
||||
|
||||
test('should be able to consume the output of `_.unzip`', function() {
|
||||
var expected = [['moe', 'larry'], [30, 40]];
|
||||
deepEqual(_.unzip(_.zip(_.unzip(_.zip(expected)))), expected);
|
||||
});
|
||||
}());
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
QUnit.module('lodash(...).shift');
|
||||
|
||||
(function() {
|
||||
|
||||
Reference in New Issue
Block a user