mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-09 10:27:49 +00:00
Reduce _.unzip and _.zip.
Former-commit-id: f388c50817910eee510f33b22fd4904fd648a6f0
This commit is contained in:
21
lodash.js
21
lodash.js
@@ -4106,17 +4106,11 @@
|
||||
*/
|
||||
function unzip(array) {
|
||||
var index = -1,
|
||||
length = array ? array.length : 0,
|
||||
tupleLength = length ? max(pluck(array, 'length')) : 0,
|
||||
result = Array(tupleLength);
|
||||
length = array ? max(pluck(array, 'length')) : 0,
|
||||
result = Array(length < 0 ? 0 : length);
|
||||
|
||||
while (++index < length) {
|
||||
var tupleIndex = -1,
|
||||
tuple = array[index];
|
||||
|
||||
while (++tupleIndex < tupleLength) {
|
||||
(result[tupleIndex] || (result[tupleIndex] = Array(length)))[index] = tuple[tupleIndex];
|
||||
}
|
||||
result[index] = pluck(array, index);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -4157,14 +4151,7 @@
|
||||
* // => [['moe', 30, true], ['larry', 40, false]]
|
||||
*/
|
||||
function zip(array) {
|
||||
var index = -1,
|
||||
length = array ? max(pluck(arguments, 'length')) : 0,
|
||||
result = Array(length);
|
||||
|
||||
while (++index < length) {
|
||||
result[index] = pluck(arguments, index);
|
||||
}
|
||||
return result;
|
||||
return array ? unzip(arguments) : [];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user