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