mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-01 07:47:49 +00:00
Simplify _.zip for the underscore build.
Former-commit-id: 18560e78f052fad5c5d7af1ef6571dd31accf690
This commit is contained in:
15
build.js
15
build.js
@@ -3598,6 +3598,21 @@
|
||||
'}'
|
||||
].join('\n'));
|
||||
}
|
||||
// replace `_.zip`
|
||||
if(!isLodashFunc('zip')) {
|
||||
source = replaceFunction(source, 'zip', [
|
||||
'function zip() {',
|
||||
' var index = -1,',
|
||||
" length = max(pluck(arguments, 'length')),",
|
||||
' result = Array(length < 0 ? 0 : length);',
|
||||
'',
|
||||
' while (++index < length) {',
|
||||
' result[index] = pluck(arguments, index);',
|
||||
' }',
|
||||
' return result;',
|
||||
'}'
|
||||
].join('\n'));
|
||||
}
|
||||
// unexpose `lodash.support`
|
||||
if (!isLodashFunc('support')) {
|
||||
source = source.replace(/\blodash\.support *= */, '');
|
||||
|
||||
7
dist/lodash.underscore.js
vendored
7
dist/lodash.underscore.js
vendored
@@ -3214,13 +3214,12 @@
|
||||
* // => [['moe', 30, true], ['larry', 40, false]]
|
||||
*/
|
||||
function zip() {
|
||||
var array = arguments.length > 1 ? arguments : arguments[0],
|
||||
index = -1,
|
||||
length = array ? max(pluck(array, 'length')) : 0,
|
||||
var index = -1,
|
||||
length = max(pluck(arguments, 'length')),
|
||||
result = Array(length < 0 ? 0 : length);
|
||||
|
||||
while (++index < length) {
|
||||
result[index] = pluck(array, index);
|
||||
result[index] = pluck(arguments, index);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
2
dist/lodash.underscore.min.js
vendored
2
dist/lodash.underscore.min.js
vendored
@@ -14,7 +14,7 @@ if(null==n||null==t)return n===t;if(o=xt.call(n),u=xt.call(t),o!=u)return!1;swit
|
||||
else for(;++i<o;)r=n[i],r>u&&(u=r);return u}function B(n,t){var r=-1,e=n?n.length:0;if(typeof e=="number")for(var u=Array(e);++r<e;)u[r]=n[r][t];return u||S(n,t)}function k(n,t,r,e){if(!n)return r;var u=3>arguments.length;t=G(t,e,4);var i=-1,o=n.length;if(typeof o=="number")for(u&&(r=n[++i]);++i<o;)r=t(r,n[i],i,n);else Ct(n,function(n,e,i){r=u?(u=!1,n):t(r,n,e,i)});return r}function q(n,t,r,e){var u=n?n.length:0,i=3>arguments.length;if(typeof u!="number")var o=$t(n),u=o.length;return t=G(t,e,4),F(n,function(e,a,f){a=o?o[--u]:--u,r=i?(i=!1,n[a]):t(r,n[a],a,f)
|
||||
}),r}function D(n,t,r){var e;t=G(t,r),r=-1;var u=n?n.length:0;if(typeof u=="number")for(;++r<u&&!(e=t(n[r],r,n)););else Ct(n,function(n,r,u){return(e=t(n,r,u))&&Q});return!!e}function R(n,t,r){return r&&m(t)?null:(r?T:E)(n,t)}function M(n){for(var t=-1,r=c(),e=n.length,u=dt.apply(ht,qt.call(arguments,1)),i=[];++t<e;){var o=n[t];0>r(u,o)&&i.push(o)}return i}function $(n,t,r){if(n){var e=0,u=n.length;if(typeof t!="number"&&null!=t){var i=-1;for(t=G(t,r);++i<u&&t(n[i],i,n);)e++}else if(e=t,null==e||r)return n[0];
|
||||
return qt.call(n,0,Bt(Nt(0,e),u))}}function z(n,t){for(var r=-1,e=n?n.length:0,u=[];++r<e;){var i=n[r];i&&typeof i=="object"&&(Mt(i)||s(i))?wt.apply(u,t?i:z(i)):u.push(i)}return u}function I(n,r,e){if(typeof e=="number"){var u=n?n.length:0;e=0>e?Nt(0,u+e):e||0}else if(e)return e=C(n,r),n[e]===r?e:-1;return n?t(n,r,e):-1}function W(n,t,r){if(typeof t!="number"&&null!=t){var e=0,u=-1,i=n?n.length:0;for(t=G(t,r);++u<i&&t(n[u],u,n);)e++}else e=null==t||r?1:Nt(0,t);return qt.call(n,e)}function C(n,t,r,e){var u=0,i=n?n.length:u;
|
||||
for(r=r?G(r,e,1):J,t=r(t);u<i;)e=u+i>>>1,r(n[e])<t?u=e+1:i=e;return u}function P(n,t,r,e){var u=-1,i=c(),o=n?n.length:0,a=[],f=a;for(typeof t!="boolean"&&null!=t&&(e=r,r=t,t=!1),null!=r&&(f=[],r=G(r,e));++u<o;){e=n[u];var l=r?r(e,u,n):e;(t?!u||f[f.length-1]!==l:0>i(f,l))&&(r&&f.push(l),a.push(e))}return a}function U(){for(var n=1<arguments.length?arguments:arguments[0],t=-1,r=n?N(B(n,"length")):0,e=Array(0>r?0:r);++t<r;)e[t]=B(n,t);return e}function V(n,t){return Rt.fastBind||At&&2<arguments.length?At.call.apply(At,arguments):a(n,t,qt.call(arguments,2))
|
||||
for(r=r?G(r,e,1):J,t=r(t);u<i;)e=u+i>>>1,r(n[e])<t?u=e+1:i=e;return u}function P(n,t,r,e){var u=-1,i=c(),o=n?n.length:0,a=[],f=a;for(typeof t!="boolean"&&null!=t&&(e=r,r=t,t=!1),null!=r&&(f=[],r=G(r,e));++u<o;){e=n[u];var l=r?r(e,u,n):e;(t?!u||f[f.length-1]!==l:0>i(f,l))&&(r&&f.push(l),a.push(e))}return a}function U(){for(var n=-1,t=N(B(arguments,"length")),r=Array(0>t?0:t);++n<t;)r[n]=B(arguments,n);return r}function V(n,t){return Rt.fastBind||At&&2<arguments.length?At.call.apply(At,arguments):a(n,t,qt.call(arguments,2))
|
||||
}function G(n,t,r){if(null==n)return J;var e=typeof n;if("function"!=e){if("object"!=e)return function(t){return t[n]};var u=$t(n);return function(t){for(var r=u.length,e=!1;r--&&(e=t[u[r]]===n[u[r]]););return e}}return typeof t=="undefined"?n:1===r?function(r){return n.call(t,r)}:2===r?function(r,e){return n.call(t,r,e)}:4===r?function(r,e,u,i){return n.call(t,r,e,u,i)}:function(r,e,u){return n.call(t,r,e,u)}}function H(n,t,r){function e(){clearTimeout(s),clearTimeout(v),l=0,s=v=null}function u(){var t=g&&(!h||1<l);
|
||||
e(),t&&(false!==p&&(c=new Date),a=n.apply(f,o))}function i(){e(),(g||p!==t)&&(c=new Date,a=n.apply(f,o))}var o,a,f,l=0,c=0,p=!1,s=null,v=null,g=!0;if(t=Nt(0,t||0),true===r)var h=!0,g=!1;else b(r)&&(h=r.leading,p="maxWait"in r&&Nt(t,r.maxWait||0),g="trailing"in r?r.trailing:g);return function(){if(o=arguments,f=this,l++,clearTimeout(v),false===p)h&&2>l&&(a=n.apply(f,o));else{var r=new Date;!s&&!h&&(c=r);var e=p-(r-c);0<e?s||(s=setTimeout(i,e)):(clearTimeout(s),s=null,c=r,a=n.apply(f,o))}return t!==p&&(v=setTimeout(u,t)),a
|
||||
}}function J(n){return n}function K(n){F(h(n),function(t){var r=i[t]=n[t];i.prototype[t]=function(){var n=[this.__wrapped__];return wt.apply(n,arguments),n=r.apply(i,n),this.__chain__&&(n=new o(n),n.__chain__=!0),n}})}var L=0,Q={},X=+new Date+"",Y=/&(?:amp|lt|gt|quot|#x27|#x2F);/g,Z=/[&<>"'\/]/g,nt=/($^)/,tt=/['\n\r\t\u2028\u2029\\]/g,rt="[object Arguments]",et="[object Array]",ut="[object Boolean]",it="[object Date]",ot="[object Number]",at="[object Object]",ft="[object RegExp]",lt="[object String]",ct={"boolean":!1,"function":!0,object:!0,number:!1,string:!1,undefined:!1},pt={"\\":"\\","'":"'","\n":"n","\r":"r","\t":"t","\u2028":"u2028","\u2029":"u2029"},st=ct[typeof exports]&&exports,vt=ct[typeof module]&&module&&module.exports==st&&module,gt=ct[typeof global]&&global;
|
||||
|
||||
@@ -1079,6 +1079,10 @@
|
||||
deepEqual(lodash.findWhere(collection, { 'a': 1 }), collection[0], '_.findWhere: ' + basename);
|
||||
strictEqual(lodash.findWhere(collection, {}), null, '_.findWhere should return `null` for falsey `properties`: ' + basename);
|
||||
|
||||
var expected = [[['moe', 30, true]], [['larry', 40, false]]];
|
||||
actual = lodash.unzip(lodash.zip(['moe', 'larry'], [30, 40], [true, false]));
|
||||
deepEqual(actual, expected, '_.zip is unable to correctly consume it\'s output: ' + basename);
|
||||
|
||||
start();
|
||||
});
|
||||
});
|
||||
@@ -1577,7 +1581,8 @@
|
||||
'uniq',
|
||||
'uniqueId',
|
||||
'value',
|
||||
'where'
|
||||
'where',
|
||||
'zip'
|
||||
];
|
||||
|
||||
function strip(value) {
|
||||
|
||||
@@ -3513,7 +3513,7 @@
|
||||
deepEqual(actual, [['moe', 30, undefined], ['larry', 40, false]]);
|
||||
});
|
||||
|
||||
test('should be able to consume the output of `_.unzip`', function() {
|
||||
test('should correctly consume it\'s output', function() {
|
||||
var expected = [['moe', 'larry'], [30, 40]];
|
||||
deepEqual(_.unzip(_.zip(_.unzip(_.zip(expected)))), expected);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user