diff --git a/build.js b/build.js index 8bb643f86..0c0186aff 100755 --- a/build.js +++ b/build.js @@ -48,6 +48,7 @@ 'include': 'contains', 'inject': 'reduce', 'methods': 'functions', + 'object': 'zipObject', 'select': 'filter', 'tail': 'rest', 'take': 'first', @@ -69,7 +70,8 @@ 'reduceRight': ['foldr'], 'rest': ['drop', 'tail'], 'some': ['any'], - 'uniq': ['unique'] + 'uniq': ['unique'], + 'zipObject': ['object'] }; /** Used to track function dependencies */ @@ -1593,7 +1595,8 @@ var exposeAssign = !isUnderscore, exposeForIn = !isUnderscore, exposeForOwn = !isUnderscore, - exposeIsPlainObject = !isUnderscore; + exposeIsPlainObject = !isUnderscore, + exposeZipObject = !isUnderscore; // flags to specify export options var isAMD = exportsOptions.indexOf('amd') > -1, @@ -1632,6 +1635,7 @@ exposeForIn = methods.indexOf('forIn') > -1; exposeForOwn = methods.indexOf('forOwn') > -1; exposeIsPlainObject = methods.indexOf('isPlainObject') > -1; + exposeZipObject = methods.indexOf('zipObject') > -1; methods = _.without.apply(_, [plusMethods].concat(minusMethods)); useUnderscoreClone = methods.indexOf('clone') < 0; @@ -2299,7 +2303,7 @@ }); } if (isUnderscore) { - // remove `_.assign`, `_.forIn`, `_.forOwn`, and `_.isPlainObject` assignments + // remove `_.assign`, `_.forIn`, `_.forOwn`, `_.isPlainObject`, and `_.zipObject` assignments (function() { var snippet = getMethodAssignments(source), modified = snippet; @@ -2316,6 +2320,9 @@ if (!exposeIsPlainObject) { modified = modified.replace(/^(?: *\/\/.*\s*)* *lodash\.isPlainObject *=.+\n/m, ''); } + if (!exposeZipObject) { + modified = modified.replace(/^(?: *\/\/.*\s*)* *lodash\.zipObject *=.+\n/m, ''); + } source = source.replace(snippet, function() { return modified; }); diff --git a/build/pre-compile.js b/build/pre-compile.js index fb8bbba61..0f114c010 100644 --- a/build/pre-compile.js +++ b/build/pre-compile.js @@ -204,6 +204,7 @@ 'without', 'wrap', 'zip', + 'zipObject', // properties used by the `backbone` and `underscore` builds '__chain__', diff --git a/dist/lodash.compat.js b/dist/lodash.compat.js index b04d4014d..d62475efb 100644 --- a/dist/lodash.compat.js +++ b/dist/lodash.compat.js @@ -698,12 +698,12 @@ }; } if (argCount === 4) { - return function(accumulator, value, index, object) { - return func.call(thisArg, accumulator, value, index, object); + return function(accumulator, value, index, collection) { + return func.call(thisArg, accumulator, value, index, collection); }; } - return function(value, index, object) { - return func.call(thisArg, value, index, object); + return function(value, index, collection) { + return func.call(thisArg, value, index, collection); }; } return func; @@ -3660,39 +3660,6 @@ return -1; } - /** - * Creates an object composed from arrays of `keys` and `values`. Pass either - * a single two dimensional array, i.e. `[[key1, value1], [key2, value2]]`, or - * two arrays, one of `keys` and one of corresponding `values`. - * - * @static - * @memberOf _ - * @category Arrays - * @param {Array} keys The array of keys. - * @param {Array} [values=[]] The array of values. - * @returns {Object} Returns an object composed of the given keys and - * corresponding values. - * @example - * - * _.object(['moe', 'larry'], [30, 40]); - * // => { 'moe': 30, 'larry': 40 } - */ - function object(keys, values) { - var index = -1, - length = keys ? keys.length : 0, - result = {}; - - while (++index < length) { - var key = keys[index]; - if (values) { - result[key] = values[index]; - } else { - result[key[0]] = key[1]; - } - } - return result; - } - /** * Creates an array of numbers (positive and/or negative) progressing from * `start` up to but not including `end`. @@ -4044,6 +4011,40 @@ return result; } + /** + * Creates an object composed from arrays of `keys` and `values`. Pass either + * a single two dimensional array, i.e. `[[key1, value1], [key2, value2]]`, or + * two arrays, one of `keys` and one of corresponding `values`. + * + * @static + * @memberOf _ + * @alias object + * @category Arrays + * @param {Array} keys The array of keys. + * @param {Array} [values=[]] The array of values. + * @returns {Object} Returns an object composed of the given keys and + * corresponding values. + * @example + * + * _.zipObject(['moe', 'larry'], [30, 40]); + * // => { 'moe': 30, 'larry': 40 } + */ + function zipObject(keys, values) { + var index = -1, + length = keys ? keys.length : 0, + result = {}; + + while (++index < length) { + var key = keys[index]; + if (values) { + result[key] = values[index]; + } else { + result[key[0]] = key[1]; + } + } + return result; + } + /*--------------------------------------------------------------------------*/ /** @@ -5003,7 +5004,6 @@ lodash.memoize = memoize; lodash.merge = merge; lodash.min = min; - lodash.object = object; lodash.omit = omit; lodash.once = once; lodash.pairs = pairs; @@ -5027,6 +5027,7 @@ lodash.without = without; lodash.wrap = wrap; lodash.zip = zip; + lodash.zipObject = zipObject; // add aliases lodash.collect = map; @@ -5034,6 +5035,7 @@ lodash.each = forEach; lodash.extend = assign; lodash.methods = functions; + lodash.object = zipObject; lodash.select = filter; lodash.tail = rest; lodash.unique = uniq; diff --git a/dist/lodash.compat.min.js b/dist/lodash.compat.min.js index 297ccee43..4abe5e3ae 100644 --- a/dist/lodash.compat.min.js +++ b/dist/lodash.compat.min.js @@ -4,40 +4,40 @@ * Build: `lodash -o ./dist/lodash.compat.js` * Underscore.js 1.4.4 underscorejs.org/LICENSE */ -;(function(n){function t(e){function o(n){return n&&typeof n=="object"&&n.__wrapped__?n:this instanceof o?(this.__wrapped__=n,void 0):new o(n)}function B(n,t,r){t||(t=0);var e=n.length,u=e-t>=(r||a);if(u){var o={};for(r=t-1;++rt||typeof n=="undefined")return 1; -if(nu;u++)e+="j='"+t.k[u]+"';if(","constructor"==t.k[u]&&(e+="!(g&&g.prototype===n)&&"),e+="i.call(n,j)){"+t.h+"}"}return(t.b||t.i)&&(e+="}"),e+=t.c+";return u",r("f,i,k,l,m,r,p","return function("+n+"){"+e+"}")(P,Ht,G,kr,rt,$,rr)}function C(n){return"\\"+F[n]}function M(n){return Ir[n]}function K(n){return typeof n.toString!="function"&&typeof(n+"")=="string"}function L(){}function U(n,t,r){t||(t=0),typeof r=="undefined"&&(r=n?n.length:0);var e=-1;r=r-t||0;for(var u=Nt(0>r?0:r);++er?er(0,u+r):r)||0,typeof u=="number"?o=-1<(rt(n)?n.indexOf(t,r):mt(n,t,r)):xr(n,function(n){return++eu&&(u=i)}}else t=!t&&rt(n)?R:P(t,r),xr(n,function(n,r,o){r=t(n,r,o),r>e&&(e=r,u=n)});return u}function st(n,t,r,e){var u=3>arguments.length;if(t=P(t,e,4),kr(n)){var o=-1,i=n.length;for(u&&(r=n[++o]);++oarguments.length;if(typeof o!="number")var f=Er(n),o=f.length;else yr&&rt(n)&&(u=n.split(""));return t=P(t,e,4),ct(n,function(n,e,a){e=f?f[--o]:--o,r=i?(i=!1,u[e]):t(r,u[e],e,a)}),r}function gt(n,t,r){var e;if(t=P(t,r),kr(n)){r=-1;for(var u=n.length;++rr?er(0,u+r):r||0)-1;else if(r)return e=_t(n,t),n[e]===t?e:-1;for(;++e>>1,r(n[e])mt(f,l))&&((r||a)&&f.push(l),i.push(e))}return i}function jt(n,t){return lr||Yt&&2/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:h,variable:"",imports:{_:o}}; -var br={a:"q,w,h",l:"var a=arguments,b=0,c=typeof h=='number'?2:a.length;while(++b":">",'"':""","'":"'"},Nr=X(Ir),Ar=z(br,{l:br.l.replace(";",";if(c>3&&typeof a[c-2]=='function'){var d=f(a[--c-1],a[c--],2);}else if(c>2&&typeof a[c-1]=='function'){d=a[--c];}"),h:"u[j]=d?d(u[j],n[j]):n[j]"}),$r=z(br);Z(/x/)&&(Z=function(n){return n instanceof Ft||Xt.call(n)==S});var Fr=Gt?function(n){if(!n||typeof n!="object")return!1;var t=n.valueOf,r=typeof t=="function"&&(r=Gt(t))&&Gt(r);return r?n==r||Gt(n)==r&&!G(n):H(n)}:H,qr=8==or("08")?or:function(n,t){return or(rt(n)?n.replace(/^0+(?=.$)/,""):n,t||0) -},Br=lt,Rr=ft;return cr&&u&&typeof Qt=="function"&&(wt=jt(Qt,e)),o.after=function(n,t){return 1>n?t():function(){return 1>--n?t.apply(this,arguments):void 0}},o.assign=Ar,o.at=function(n){var t=-1,r=Ut.apply(Pt,U(arguments,1)),e=r.length,u=Nt(e);for(yr&&rt(n)&&(n=n.split(""));++tmt(a,c)){i&&a.push(c);for(var p=r;--p;)if(!(e[p]||(e[p]=B(t[p],0,100)))(c))continue n;f.push(c)}}return f},o.invert=X,o.invoke=function(n,t){var r=U(arguments,2),e=-1,u=typeof t=="function",o=n?n.length:0,i=Nt(typeof o=="number"?o:0); -return ct(n,function(n){i[++e]=(u?t:n[t]).apply(n,r)}),i},o.keys=Er,o.map=lt,o.max=pt,o.memoize=function(n,t){var r={};return function(){var e=(t?t.apply(this,arguments):arguments[0])+"";return Ht.call(r,e)?r[e]:r[e]=n.apply(this,arguments)}},o.merge=et,o.min=function(n,t,r){var e=1/0,u=e;if(!t&&kr(n)){r=-1;for(var o=n.length;++rmt(o,r,1))&&(u[r]=n)}),u},o.once=function(n){var t,r;return function(){return t?r:(t=!0,r=n.apply(this,arguments),n=null,r)}},o.pairs=function(n){for(var t=-1,r=Er(n),e=r.length,u=Nt(e);++tr?er(0,e+r):ur(r,e-1))+1);e--;)if(n[e]===t)return e;return-1},o.mixin=Ot,o.noConflict=function(){return e._=Ct,this},o.parseInt=qr,o.random=function(n,t){return null==n&&null==t&&(t=1),n=+n||0,null==t&&(t=n,n=0),n+Vt(ir()*((+t||0)-n+1))},o.reduce=st,o.reduceRight=vt,o.result=function(n,t){var e=n?n[t]:r;return Z(e)?n[t]():e},o.runInContext=t,o.size=function(n){var t=n?n.length:0;return typeof t=="number"?t:Er(n).length -},o.some=gt,o.sortedIndex=_t,o.template=function(n,t,e){var u=o.templateSettings;n||(n=""),e=$r({},e,u);var i,f=$r({},e.imports,u.imports),u=Er(f),f=ut(f),a=0,c=e.interpolate||y,v="__p+='",c=Tt((e.escape||y).source+"|"+c.source+"|"+(c===h?g:y).source+"|"+(e.evaluate||y).source+"|$","g");n.replace(c,function(t,r,e,u,o,f){return e||(e=u),v+=n.slice(a,f).replace(d,C),r&&(v+="'+__e("+r+")+'"),o&&(i=!0,v+="';"+o+";__p+='"),e&&(v+="'+((__t=("+e+"))==null?'':__t)+'"),a=f+t.length,t}),v+="';\n",c=e=e.variable,c||(e="obj",v="with("+e+"){"+v+"}"),v=(i?v.replace(l,""):v).replace(p,"$1").replace(s,"$1;"),v="function("+e+"){"+(c?"":e+"||("+e+"={});")+"var __t,__p='',__e=_.escape"+(i?",__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}":";")+v+"return __p}"; -try{var m=Ft(u,"return "+v).apply(r,f)}catch(_){throw _.source=v,_}return t?m(t):(m.source=v,m)},o.unescape=function(n){return null==n?"":(n+"").replace(c,V)},o.uniqueId=function(n){var t=++i;return(null==n?"":n+"")+t},o.all=it,o.any=gt,o.detect=at,o.foldl=st,o.foldr=vt,o.include=ot,o.inject=st,Sr(o,function(n,t){o.prototype[t]||(o.prototype[t]=function(){var t=[this.__wrapped__];return Jt.apply(t,arguments),n.apply(o,t)})}),o.first=ht,o.last=function(n,t,r){if(n){var e=0,u=n.length;if(typeof t!="number"&&null!=t){var o=u; -for(t=P(t,r);o--&&t(n[o],o,n);)e++}else if(e=t,null==e||r)return n[u-1];return U(n,er(0,u-e))}},o.take=ht,o.head=ht,Sr(o,function(n,t){o.prototype[t]||(o.prototype[t]=function(t,r){var e=n(this.__wrapped__,t,r);return null==t||r&&typeof t!="function"?e:new o(e)})}),o.VERSION="1.0.1",o.prototype.toString=function(){return this.__wrapped__+""},o.prototype.value=St,o.prototype.valueOf=St,xr(["join","pop","shift"],function(n){var t=Pt[n];o.prototype[n]=function(){return t.apply(this.__wrapped__,arguments) -}}),xr(["push","reverse","sort","unshift"],function(n){var t=Pt[n];o.prototype[n]=function(){return t.apply(this.__wrapped__,arguments),this}}),xr(["concat","slice","splice"],function(n){var t=Pt[n];o.prototype[n]=function(){return new o(t.apply(this.__wrapped__,arguments))}}),sr&&xr(["pop","shift","splice"],function(n){var t=Pt[n],r="splice"==n;o.prototype[n]=function(){var n=this.__wrapped__,e=t.apply(n,arguments);return 0===n.length&&delete n[0],r?new o(e):e}}),o}var r,e=typeof exports=="object"&&exports,u=typeof module=="object"&&module&&module.exports==e&&module,o=typeof global=="object"&&global; +;(function(n){function t(e){function o(n){return n&&typeof n=="object"&&n.__wrapped__?n:this instanceof o?(this.__wrapped__=n,void 0):new o(n)}function B(n,t,r){t||(t=0);var e=n.length,u=e-t>=(r||a);if(u){var o={};for(r=t-1;++rt||typeof n=="undefined")return 1; +if(nu;u++)e+="j='"+t.k[u]+"';if(","constructor"==t.k[u]&&(e+="!(g&&g.prototype===n)&&"),e+="i.call(n,j)){"+t.h+"}"}return(t.b||t.i)&&(e+="}"),e+=t.c+";return u",r("f,i,k,l,m,r,p","return function("+n+"){"+e+"}")(P,Jt,G,Er,rt,$,er)}function C(n){return"\\"+F[n]}function M(n){return Nr[n]}function K(n){return typeof n.toString!="function"&&typeof(n+"")=="string"}function L(){}function U(n,t,r){t||(t=0),typeof r=="undefined"&&(r=n?n.length:0);var e=-1;r=r-t||0;for(var u=At(0>r?0:r);++er?ur(0,u+r):r)||0,typeof u=="number"?o=-1<(rt(n)?n.indexOf(t,r):mt(n,t,r)):Or(n,function(n){return++eu&&(u=i)}}else t=!t&&rt(n)?R:P(t,r),Or(n,function(n,r,o){r=t(n,r,o),r>e&&(e=r,u=n)});return u}function st(n,t,r,e){var u=3>arguments.length;if(t=P(t,e,4),Er(n)){var o=-1,i=n.length;for(u&&(r=n[++o]);++oarguments.length;if(typeof o!="number")var f=Ir(n),o=f.length;else mr&&rt(n)&&(u=n.split(""));return t=P(t,e,4),ct(n,function(n,e,a){e=f?f[--o]:--o,r=i?(i=!1,u[e]):t(r,u[e],e,a)}),r}function gt(n,t,r){var e;if(t=P(t,r),Er(n)){r=-1;for(var u=n.length;++rr?ur(0,u+r):r||0)-1;else if(r)return e=_t(n,t),n[e]===t?e:-1;for(;++e>>1,r(n[e])mt(f,l))&&((r||a)&&f.push(l),i.push(e))}return i}function jt(n,t){for(var r=-1,e=n?n.length:0,u={};++r/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:h,variable:"",imports:{_:o}}; +var jr={a:"q,w,h",l:"var a=arguments,b=0,c=typeof h=='number'?2:a.length;while(++b":">",'"':""","'":"'"},Ar=X(Nr),$r=z(jr,{l:jr.l.replace(";",";if(c>3&&typeof a[c-2]=='function'){var d=f(a[--c-1],a[c--],2);}else if(c>2&&typeof a[c-1]=='function'){d=a[--c];}"),h:"u[j]=d?d(u[j],n[j]):n[j]"}),Fr=z(jr);Z(/x/)&&(Z=function(n){return n instanceof qt||Yt.call(n)==S});var qr=Ht?function(n){if(!n||typeof n!="object")return!1;var t=n.valueOf,r=typeof t=="function"&&(r=Ht(t))&&Ht(r);return r?n==r||Ht(n)==r&&!G(n):H(n)}:H,Br=8==ir("08")?ir:function(n,t){return ir(rt(n)?n.replace(/^0+(?=.$)/,""):n,t||0) +},Rr=lt,Tr=ft;return lr&&u&&typeof Wt=="function"&&(xt=wt(Wt,e)),o.after=function(n,t){return 1>n?t():function(){return 1>--n?t.apply(this,arguments):void 0}},o.assign=$r,o.at=function(n){var t=-1,r=Vt.apply(zt,U(arguments,1)),e=r.length,u=At(e);for(mr&&rt(n)&&(n=n.split(""));++tmt(a,c)){i&&a.push(c);for(var p=r;--p;)if(!(e[p]||(e[p]=B(t[p],0,100)))(c))continue n;f.push(c)}}return f},o.invert=X,o.invoke=function(n,t){var r=U(arguments,2),e=-1,u=typeof t=="function",o=n?n.length:0,i=At(typeof o=="number"?o:0); +return ct(n,function(n){i[++e]=(u?t:n[t]).apply(n,r)}),i},o.keys=Ir,o.map=lt,o.max=pt,o.memoize=function(n,t){var r={};return function(){var e=(t?t.apply(this,arguments):arguments[0])+"";return Jt.call(r,e)?r[e]:r[e]=n.apply(this,arguments)}},o.merge=et,o.min=function(n,t,r){var e=1/0,u=e;if(!t&&Er(n)){r=-1;for(var o=n.length;++rmt(o,r,1))&&(u[r]=n)}),u},o.once=function(n){var t,r;return function(){return t?r:(t=!0,r=n.apply(this,arguments),n=null,r)}},o.pairs=function(n){for(var t=-1,r=Ir(n),e=r.length,u=At(e);++tr?ur(0,e+r):or(r,e-1))+1);e--;)if(n[e]===t)return e;return-1},o.mixin=St,o.noConflict=function(){return e._=Mt,this +},o.parseInt=Br,o.random=function(n,t){return null==n&&null==t&&(t=1),n=+n||0,null==t&&(t=n,n=0),n+Gt(fr()*((+t||0)-n+1))},o.reduce=st,o.reduceRight=vt,o.result=function(n,t){var e=n?n[t]:r;return Z(e)?n[t]():e},o.runInContext=t,o.size=function(n){var t=n?n.length:0;return typeof t=="number"?t:Ir(n).length},o.some=gt,o.sortedIndex=_t,o.template=function(n,t,e){var u=o.templateSettings;n||(n=""),e=Fr({},e,u);var i,f=Fr({},e.imports,u.imports),u=Ir(f),f=ut(f),a=0,c=e.interpolate||y,v="__p+='",c=Dt((e.escape||y).source+"|"+c.source+"|"+(c===h?g:y).source+"|"+(e.evaluate||y).source+"|$","g"); +n.replace(c,function(t,r,e,u,o,f){return e||(e=u),v+=n.slice(a,f).replace(d,C),r&&(v+="'+__e("+r+")+'"),o&&(i=!0,v+="';"+o+";__p+='"),e&&(v+="'+((__t=("+e+"))==null?'':__t)+'"),a=f+t.length,t}),v+="';\n",c=e=e.variable,c||(e="obj",v="with("+e+"){"+v+"}"),v=(i?v.replace(l,""):v).replace(p,"$1").replace(s,"$1;"),v="function("+e+"){"+(c?"":e+"||("+e+"={});")+"var __t,__p='',__e=_.escape"+(i?",__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}":";")+v+"return __p}";try{var m=qt(u,"return "+v).apply(r,f) +}catch(_){throw _.source=v,_}return t?m(t):(m.source=v,m)},o.unescape=function(n){return null==n?"":(n+"").replace(c,V)},o.uniqueId=function(n){var t=++i;return(null==n?"":n+"")+t},o.all=it,o.any=gt,o.detect=at,o.foldl=st,o.foldr=vt,o.include=ot,o.inject=st,kr(o,function(n,t){o.prototype[t]||(o.prototype[t]=function(){var t=[this.__wrapped__];return Qt.apply(t,arguments),n.apply(o,t)})}),o.first=ht,o.last=function(n,t,r){if(n){var e=0,u=n.length;if(typeof t!="number"&&null!=t){var o=u;for(t=P(t,r);o--&&t(n[o],o,n);)e++ +}else if(e=t,null==e||r)return n[u-1];return U(n,ur(0,u-e))}},o.take=ht,o.head=ht,kr(o,function(n,t){o.prototype[t]||(o.prototype[t]=function(t,r){var e=n(this.__wrapped__,t,r);return null==t||r&&typeof t!="function"?e:new o(e)})}),o.VERSION="1.0.1",o.prototype.toString=function(){return this.__wrapped__+""},o.prototype.value=kt,o.prototype.valueOf=kt,Or(["join","pop","shift"],function(n){var t=zt[n];o.prototype[n]=function(){return t.apply(this.__wrapped__,arguments)}}),Or(["push","reverse","sort","unshift"],function(n){var t=zt[n]; +o.prototype[n]=function(){return t.apply(this.__wrapped__,arguments),this}}),Or(["concat","slice","splice"],function(n){var t=zt[n];o.prototype[n]=function(){return new o(t.apply(this.__wrapped__,arguments))}}),vr&&Or(["pop","shift","splice"],function(n){var t=zt[n],r="splice"==n;o.prototype[n]=function(){var n=this.__wrapped__,e=t.apply(n,arguments);return 0===n.length&&delete n[0],r?new o(e):e}}),o}var r,e=typeof exports=="object"&&exports,u=typeof module=="object"&&module&&module.exports==e&&module,o=typeof global=="object"&&global; o.global===o&&(n=o);var i=0,f={},a=30,c=/&(?:amp|lt|gt|quot|#39);/g,l=/\b__p\+='';/g,p=/\b(__p\+=)''\+/g,s=/(__e\(.*?\)|\b__t\))\+'';/g,v=/\w*$/,g=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,h=/<%=([\s\S]+?)%>/g,y=/($^)/,m=/[&<>"']/g,d=/['\n\r\t\u2028\u2029\\]/g,_="Array Boolean Date Function Math Number Object RegExp String _ attachEvent clearTimeout isFinite isNaN parseInt setImmediate setTimeout".split(" "),b="constructor hasOwnProperty isPrototypeOf propertyIsEnumerable toLocaleString toString valueOf".split(" "),j="[object Arguments]",w="[object Array]",x="[object Boolean]",O="[object Date]",S="[object Function]",k="[object Number]",E="[object Object]",I="[object RegExp]",N="[object String]",A={}; A[S]=!1,A[j]=A[w]=A[x]=A[O]=A[k]=A[E]=A[I]=A[N]=!0;var $={"boolean":!1,"function":!0,object:!0,number:!1,string:!1,undefined:!1},F={"\\":"\\","'":"'","\n":"n","\r":"r"," ":"t","\u2028":"u2028","\u2029":"u2029"},q=t();typeof define=="function"&&typeof define.amd=="object"&&define.amd?(n._=q,define(function(){return q})):e&&!e.nodeType?u?(u.exports=q)._=q:e._=q:n._=q})(this); \ No newline at end of file diff --git a/dist/lodash.js b/dist/lodash.js index 001a553d2..6af517237 100644 --- a/dist/lodash.js +++ b/dist/lodash.js @@ -580,12 +580,12 @@ }; } if (argCount === 4) { - return function(accumulator, value, index, object) { - return func.call(thisArg, accumulator, value, index, object); + return function(accumulator, value, index, collection) { + return func.call(thisArg, accumulator, value, index, collection); }; } - return function(value, index, object) { - return func.call(thisArg, value, index, object); + return function(value, index, collection) { + return func.call(thisArg, value, index, collection); }; } return func; @@ -3504,39 +3504,6 @@ return -1; } - /** - * Creates an object composed from arrays of `keys` and `values`. Pass either - * a single two dimensional array, i.e. `[[key1, value1], [key2, value2]]`, or - * two arrays, one of `keys` and one of corresponding `values`. - * - * @static - * @memberOf _ - * @category Arrays - * @param {Array} keys The array of keys. - * @param {Array} [values=[]] The array of values. - * @returns {Object} Returns an object composed of the given keys and - * corresponding values. - * @example - * - * _.object(['moe', 'larry'], [30, 40]); - * // => { 'moe': 30, 'larry': 40 } - */ - function object(keys, values) { - var index = -1, - length = keys ? keys.length : 0, - result = {}; - - while (++index < length) { - var key = keys[index]; - if (values) { - result[key] = values[index]; - } else { - result[key[0]] = key[1]; - } - } - return result; - } - /** * Creates an array of numbers (positive and/or negative) progressing from * `start` up to but not including `end`. @@ -3888,6 +3855,40 @@ return result; } + /** + * Creates an object composed from arrays of `keys` and `values`. Pass either + * a single two dimensional array, i.e. `[[key1, value1], [key2, value2]]`, or + * two arrays, one of `keys` and one of corresponding `values`. + * + * @static + * @memberOf _ + * @alias object + * @category Arrays + * @param {Array} keys The array of keys. + * @param {Array} [values=[]] The array of values. + * @returns {Object} Returns an object composed of the given keys and + * corresponding values. + * @example + * + * _.zipObject(['moe', 'larry'], [30, 40]); + * // => { 'moe': 30, 'larry': 40 } + */ + function zipObject(keys, values) { + var index = -1, + length = keys ? keys.length : 0, + result = {}; + + while (++index < length) { + var key = keys[index]; + if (values) { + result[key] = values[index]; + } else { + result[key[0]] = key[1]; + } + } + return result; + } + /*--------------------------------------------------------------------------*/ /** @@ -4847,7 +4848,6 @@ lodash.memoize = memoize; lodash.merge = merge; lodash.min = min; - lodash.object = object; lodash.omit = omit; lodash.once = once; lodash.pairs = pairs; @@ -4871,6 +4871,7 @@ lodash.without = without; lodash.wrap = wrap; lodash.zip = zip; + lodash.zipObject = zipObject; // add aliases lodash.collect = map; @@ -4878,6 +4879,7 @@ lodash.each = forEach; lodash.extend = assign; lodash.methods = functions; + lodash.object = zipObject; lodash.select = filter; lodash.tail = rest; lodash.unique = uniq; diff --git a/dist/lodash.min.js b/dist/lodash.min.js index 700324cd1..dc41996b9 100644 --- a/dist/lodash.min.js +++ b/dist/lodash.min.js @@ -4,38 +4,38 @@ * Build: `lodash modern -o ./dist/lodash.js` * Underscore.js 1.4.4 underscorejs.org/LICENSE */ -;(function(n){function t(i){function a(n){if(!n||typeof n!="object")return o;var t=n.valueOf,r=typeof t=="function"&&(r=Ut(t))&&Ut(r);if(r)n=n==r||Ut(n)==r&&!J(n);else{var e=o;!n||typeof n!="object"||J(n)?n=e:(t=n.constructor,!Z(t)||t instanceof t?(ar(n,function(n,t){e=t}),n=e===o||Vt.call(n,e)):n=e)}return n}function R(n){return n&&typeof n=="object"&&n.__wrapped__?n:this instanceof R?(this.__wrapped__=n,void 0):new R(n)}function T(n,t,r){t||(t=0);var e=n.length,u=e-t>=(r||p);if(u){var o={};for(r=t-1;++rt||typeof n=="undefined")return 1;if(nr?0:r);++er?nr(0,u+r):r)||0,typeof u=="number"?i=-1<(rt(n)?n.indexOf(t,r):mt(n,t,r)):fr(n,function(n){return++eu&&(u=i)}}else t=!t&&rt(n)?D:P(t,r),fr(n,function(n,r,o){r=t(n,r,o),r>e&&(e=r,u=n)});return u}function st(n,t,r,e){var u=3>arguments.length;if(t=P(t,e,4),lr(n)){var i=-1,f=n.length;for(u&&(r=n[++i]);++iarguments.length;if(typeof u!="number")var f=pr(n),u=f.length;return t=P(t,e,4),ct(n,function(e,a,c){a=f?f[--u]:--u,r=i?(i=o,n[a]):t(r,n[a],a,c)}),r}function gt(n,t,r){var e;if(t=P(t,r),lr(n)){r=-1;for(var u=n.length;++rr?nr(0,u+r):r||0)-1;else if(r)return e=_t(n,t),n[e]===t?e:-1;for(;++e>>1,r(n[e])mt(a,p))&&((r||c)&&a.push(p),f.push(e))}return f}function jt(n,t){return ur||Qt&&2/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:d,variable:"",imports:{_:R}};var At={a:"q,w,h",l:"var a=arguments,b=0,c=typeof h=='number'?2:a.length;while(++b":">",'"':""","'":"'"},vr=X(sr),gr=M(At,{l:At.l.replace(";",";if(c>3&&typeof a[c-2]=='function'){var d=f(a[--c-1],a[c--],2);}else if(c>2&&typeof a[c-1]=='function'){d=a[--c];}"),h:"u[j]=d?d(u[j],n[j]):n[j]"}),hr=M(At),Wt=8==rr("08")?rr:function(n,t){return rr(rt(n)?n.replace(/^0+(?=.$)/,""):n,t||0)};return kt&&f&&typeof Ht=="function"&&(wt=jt(Ht,i)),R.after=function(n,t){return 1>n?t():function(){return 1>--n?t.apply(this,arguments):void 0 -}},R.assign=gr,R.at=function(n){for(var t=-1,r=Mt.apply(Rt,G(arguments,1)),e=r.length,u=St(e);++tmt(a,c)){i&&a.push(c);for(var p=r;--p;)if(!(e[p]||(e[p]=T(t[p],0,100)))(c))continue n;f.push(c)}}return f},R.invert=X,R.invoke=function(n,t){var r=G(arguments,2),e=-1,u=typeof t=="function",o=n?n.length:0,i=St(typeof o=="number"?o:0);return ct(n,function(n){i[++e]=(u?t:n[t]).apply(n,r)}),i},R.keys=pr,R.map=lt,R.max=pt,R.memoize=function(n,t){var r={};return function(){var e=(t?t.apply(this,arguments):arguments[0])+""; -return Vt.call(r,e)?r[e]:r[e]=n.apply(this,arguments)}},R.merge=et,R.min=function(n,t,r){var e=1/0,u=e;if(!t&&lr(n)){r=-1;for(var o=n.length;++rmt(o,r,1))&&(u[r]=n) -}),u},R.once=function(n){var t,r;return function(){return t?r:(t=e,r=n.apply(this,arguments),n=u,r)}},R.pairs=function(n){for(var t=-1,r=pr(n),e=r.length,u=St(e);++tr?nr(0,e+r):tr(r,e-1))+1);e--;)if(n[e]===t)return e;return-1},R.mixin=Ot,R.noConflict=function(){return i._=Dt,this},R.parseInt=Wt,R.random=function(n,t){return n==u&&t==u&&(t=1),n=+n||0,t==u&&(t=n,n=0),n+Kt(er()*((+t||0)-n+1)) -},R.reduce=st,R.reduceRight=vt,R.result=function(n,t){var e=n?n[t]:r;return Z(e)?n[t]():e},R.runInContext=t,R.size=function(n){var t=n?n.length:0;return typeof t=="number"?t:pr(n).length},R.some=gt,R.sortedIndex=_t,R.template=function(n,t,u){var o=R.templateSettings;n||(n=""),u=hr({},u,o);var i,f=hr({},u.imports,o.imports),o=pr(f),f=ut(f),a=0,c=u.interpolate||_,l="__p+='",c=qt((u.escape||_).source+"|"+c.source+"|"+(c===d?m:_).source+"|"+(u.evaluate||_).source+"|$","g");n.replace(c,function(t,r,u,o,f,c){return u||(u=o),l+=n.slice(a,c).replace(j,K),r&&(l+="'+__e("+r+")+'"),f&&(i=e,l+="';"+f+";__p+='"),u&&(l+="'+((__t=("+u+"))==null?'':__t)+'"),a=c+t.length,t -}),l+="';\n",c=u=u.variable,c||(u="obj",l="with("+u+"){"+l+"}"),l=(i?l.replace(v,""):l).replace(g,"$1").replace(h,"$1;"),l="function("+u+"){"+(c?"":u+"||("+u+"={});")+"var __t,__p='',__e=_.escape"+(i?",__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}":";")+l+"return __p}";try{var p=It(o,"return "+l).apply(r,f)}catch(s){throw s.source=l,s}return t?p(t):(p.source=l,p)},R.unescape=function(n){return n==u?"":(n+"").replace(s,H)},R.uniqueId=function(n){var t=++c;return(n==u?"":n+"")+t -},R.all=it,R.any=gt,R.detect=at,R.foldl=st,R.foldr=vt,R.include=ot,R.inject=st,cr(R,function(n,t){R.prototype[t]||(R.prototype[t]=function(){var t=[this.__wrapped__];return Gt.apply(t,arguments),n.apply(R,t)})}),R.first=ht,R.last=function(n,t,r){if(n){var e=0,o=n.length;if(typeof t!="number"&&t!=u){var i=o;for(t=P(t,r);i--&&t(n[i],i,n);)e++}else if(e=t,e==u||r)return n[o-1];return G(n,nr(0,o-e))}},R.take=ht,R.head=ht,cr(R,function(n,t){R.prototype[t]||(R.prototype[t]=function(t,r){var e=n(this.__wrapped__,t,r); -return t==u||r&&typeof t!="function"?e:new R(e)})}),R.VERSION="1.0.1",R.prototype.toString=function(){return this.__wrapped__+""},R.prototype.value=Nt,R.prototype.valueOf=Nt,fr(["join","pop","shift"],function(n){var t=Rt[n];R.prototype[n]=function(){return t.apply(this.__wrapped__,arguments)}}),fr(["push","reverse","sort","unshift"],function(n){var t=Rt[n];R.prototype[n]=function(){return t.apply(this.__wrapped__,arguments),this}}),fr(["concat","slice","splice"],function(n){var t=Rt[n];R.prototype[n]=function(){return new R(t.apply(this.__wrapped__,arguments)) +;(function(n){function t(i){function a(n){if(!n||typeof n!="object")return o;var t=n.valueOf,r=typeof t=="function"&&(r=Vt(t))&&Vt(r);if(r)n=n==r||Vt(n)==r&&!J(n);else{var e=o;!n||typeof n!="object"||J(n)?n=e:(t=n.constructor,!Z(t)||t instanceof t?(cr(n,function(n,t){e=t}),n=e===o||Gt.call(n,e)):n=e)}return n}function R(n){return n&&typeof n=="object"&&n.__wrapped__?n:this instanceof R?(this.__wrapped__=n,void 0):new R(n)}function T(n,t,r){t||(t=0);var e=n.length,u=e-t>=(r||p);if(u){var o={};for(r=t-1;++rt||typeof n=="undefined")return 1;if(nr?0:r);++er?tr(0,u+r):r)||0,typeof u=="number"?i=-1<(rt(n)?n.indexOf(t,r):mt(n,t,r)):ar(n,function(n){return++eu&&(u=i)}}else t=!t&&rt(n)?D:P(t,r),ar(n,function(n,r,o){r=t(n,r,o),r>e&&(e=r,u=n)});return u}function st(n,t,r,e){var u=3>arguments.length;if(t=P(t,e,4),pr(n)){var i=-1,f=n.length;for(u&&(r=n[++i]);++iarguments.length;if(typeof u!="number")var f=sr(n),u=f.length;return t=P(t,e,4),ct(n,function(e,a,c){a=f?f[--u]:--u,r=i?(i=o,n[a]):t(r,n[a],a,c)}),r}function gt(n,t,r){var e;if(t=P(t,r),pr(n)){r=-1;for(var u=n.length;++rr?tr(0,u+r):r||0)-1;else if(r)return e=_t(n,t),n[e]===t?e:-1;for(;++e>>1,r(n[e])mt(a,p))&&((r||c)&&a.push(p),f.push(e))}return f}function jt(n,t){for(var r=-1,e=n?n.length:0,u={};++r/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:d,variable:"",imports:{_:R}};var Et={a:"q,w,h",l:"var a=arguments,b=0,c=typeof h=='number'?2:a.length;while(++b":">",'"':""","'":"'"},gr=X(vr),hr=M(Et,{l:Et.l.replace(";",";if(c>3&&typeof a[c-2]=='function'){var d=f(a[--c-1],a[c--],2);}else if(c>2&&typeof a[c-1]=='function'){d=a[--c];}"),h:"u[j]=d?d(u[j],n[j]):n[j]"}),yr=M(Et),Xt=8==er("08")?er:function(n,t){return er(rt(n)?n.replace(/^0+(?=.$)/,""):n,t||0)};return $t&&f&&typeof Jt=="function"&&(xt=wt(Jt,i)),R.after=function(n,t){return 1>n?t():function(){return 1>--n?t.apply(this,arguments):void 0 +}},R.assign=hr,R.at=function(n){for(var t=-1,r=Kt.apply(Tt,G(arguments,1)),e=r.length,u=At(e);++tmt(a,c)){i&&a.push(c);for(var p=r;--p;)if(!(e[p]||(e[p]=T(t[p],0,100)))(c))continue n;f.push(c)}}return f},R.invert=X,R.invoke=function(n,t){var r=G(arguments,2),e=-1,u=typeof t=="function",o=n?n.length:0,i=At(typeof o=="number"?o:0);return ct(n,function(n){i[++e]=(u?t:n[t]).apply(n,r)}),i},R.keys=sr,R.map=lt,R.max=pt,R.memoize=function(n,t){var r={};return function(){var e=(t?t.apply(this,arguments):arguments[0])+""; +return Gt.call(r,e)?r[e]:r[e]=n.apply(this,arguments)}},R.merge=et,R.min=function(n,t,r){var e=1/0,u=e;if(!t&&pr(n)){r=-1;for(var o=n.length;++rmt(o,r,1))&&(u[r]=n)}),u},R.once=function(n){var t,r;return function(){return t?r:(t=e,r=n.apply(this,arguments),n=u,r) +}},R.pairs=function(n){for(var t=-1,r=sr(n),e=r.length,u=At(e);++tr?tr(0,e+r):rr(r,e-1))+1);e--;)if(n[e]===t)return e;return-1},R.mixin=Nt,R.noConflict=function(){return i._=zt,this},R.parseInt=Xt,R.random=function(n,t){return n==u&&t==u&&(t=1),n=+n||0,t==u&&(t=n,n=0),n+Ut(ur()*((+t||0)-n+1)) +},R.reduce=st,R.reduceRight=vt,R.result=function(n,t){var e=n?n[t]:r;return Z(e)?n[t]():e},R.runInContext=t,R.size=function(n){var t=n?n.length:0;return typeof t=="number"?t:sr(n).length},R.some=gt,R.sortedIndex=_t,R.template=function(n,t,u){var o=R.templateSettings;n||(n=""),u=yr({},u,o);var i,f=yr({},u.imports,o.imports),o=sr(f),f=ut(f),a=0,c=u.interpolate||_,l="__p+='",c=Bt((u.escape||_).source+"|"+c.source+"|"+(c===d?m:_).source+"|"+(u.evaluate||_).source+"|$","g");n.replace(c,function(t,r,u,o,f,c){return u||(u=o),l+=n.slice(a,c).replace(j,K),r&&(l+="'+__e("+r+")+'"),f&&(i=e,l+="';"+f+";__p+='"),u&&(l+="'+((__t=("+u+"))==null?'':__t)+'"),a=c+t.length,t +}),l+="';\n",c=u=u.variable,c||(u="obj",l="with("+u+"){"+l+"}"),l=(i?l.replace(v,""):l).replace(g,"$1").replace(h,"$1;"),l="function("+u+"){"+(c?"":u+"||("+u+"={});")+"var __t,__p='',__e=_.escape"+(i?",__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}":";")+l+"return __p}";try{var p=kt(o,"return "+l).apply(r,f)}catch(s){throw s.source=l,s}return t?p(t):(p.source=l,p)},R.unescape=function(n){return n==u?"":(n+"").replace(s,H)},R.uniqueId=function(n){var t=++c;return(n==u?"":n+"")+t +},R.all=it,R.any=gt,R.detect=at,R.foldl=st,R.foldr=vt,R.include=ot,R.inject=st,lr(R,function(n,t){R.prototype[t]||(R.prototype[t]=function(){var t=[this.__wrapped__];return Ht.apply(t,arguments),n.apply(R,t)})}),R.first=ht,R.last=function(n,t,r){if(n){var e=0,o=n.length;if(typeof t!="number"&&t!=u){var i=o;for(t=P(t,r);i--&&t(n[i],i,n);)e++}else if(e=t,e==u||r)return n[o-1];return G(n,tr(0,o-e))}},R.take=ht,R.head=ht,lr(R,function(n,t){R.prototype[t]||(R.prototype[t]=function(t,r){var e=n(this.__wrapped__,t,r); +return t==u||r&&typeof t!="function"?e:new R(e)})}),R.VERSION="1.0.1",R.prototype.toString=function(){return this.__wrapped__+""},R.prototype.value=St,R.prototype.valueOf=St,ar(["join","pop","shift"],function(n){var t=Tt[n];R.prototype[n]=function(){return t.apply(this.__wrapped__,arguments)}}),ar(["push","reverse","sort","unshift"],function(n){var t=Tt[n];R.prototype[n]=function(){return t.apply(this.__wrapped__,arguments),this}}),ar(["concat","slice","splice"],function(n){var t=Tt[n];R.prototype[n]=function(){return new R(t.apply(this.__wrapped__,arguments)) }}),R}var r,e=!0,u=null,o=!1,i=typeof exports=="object"&&exports,f=typeof module=="object"&&module&&module.exports==i&&module,a=typeof global=="object"&&global;a.global===a&&(n=a);var c=0,l={},p=30,s=/&(?:amp|lt|gt|quot|#39);/g,v=/\b__p\+='';/g,g=/\b(__p\+=)''\+/g,h=/(__e\(.*?\)|\b__t\))\+'';/g,y=/\w*$/,m=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,d=/<%=([\s\S]+?)%>/g,_=/($^)/,b=/[&<>"']/g,j=/['\n\r\t\u2028\u2029\\]/g,w="Array Boolean Date Function Math Number Object RegExp String _ attachEvent clearTimeout isFinite isNaN parseInt setImmediate setTimeout".split(" "),x="[object Arguments]",O="[object Array]",N="[object Boolean]",S="[object Date]",A="[object Number]",E="[object Object]",I="[object RegExp]",k="[object String]",$={"[object Function]":o}; $[x]=$[O]=$[N]=$[S]=$[A]=$[E]=$[I]=$[k]=e;var F={"boolean":o,"function":e,object:e,number:o,string:o,undefined:o},q={"\\":"\\","'":"'","\n":"n","\r":"r"," ":"t","\u2028":"u2028","\u2029":"u2029"},B=t();typeof define=="function"&&typeof define.amd=="object"&&define.amd?(n._=B,define(function(){return B})):i&&!i.nodeType?f?(f.exports=B)._=B:i._=B:n._=B})(this); \ No newline at end of file diff --git a/dist/lodash.underscore.js b/dist/lodash.underscore.js index bc173334e..a5fa88d49 100644 --- a/dist/lodash.underscore.js +++ b/dist/lodash.underscore.js @@ -395,12 +395,12 @@ }; } if (argCount === 4) { - return function(accumulator, value, index, object) { - return func.call(thisArg, accumulator, value, index, object); + return function(accumulator, value, index, collection) { + return func.call(thisArg, accumulator, value, index, collection); }; } - return function(value, index, object) { - return func.call(thisArg, value, index, object); + return function(value, index, collection) { + return func.call(thisArg, value, index, collection); }; } return func; @@ -2895,39 +2895,6 @@ return -1; } - /** - * Creates an object composed from arrays of `keys` and `values`. Pass either - * a single two dimensional array, i.e. `[[key1, value1], [key2, value2]]`, or - * two arrays, one of `keys` and one of corresponding `values`. - * - * @static - * @memberOf _ - * @category Arrays - * @param {Array} keys The array of keys. - * @param {Array} [values=[]] The array of values. - * @returns {Object} Returns an object composed of the given keys and - * corresponding values. - * @example - * - * _.object(['moe', 'larry'], [30, 40]); - * // => { 'moe': 30, 'larry': 40 } - */ - function object(keys, values) { - var index = -1, - length = keys ? keys.length : 0, - result = {}; - - while (++index < length) { - var key = keys[index]; - if (values) { - result[key] = values[index]; - } else { - result[key[0]] = key[1]; - } - } - return result; - } - /** * Creates an array of numbers (positive and/or negative) progressing from * `start` up to but not including `end`. @@ -3266,6 +3233,40 @@ return result; } + /** + * Creates an object composed from arrays of `keys` and `values`. Pass either + * a single two dimensional array, i.e. `[[key1, value1], [key2, value2]]`, or + * two arrays, one of `keys` and one of corresponding `values`. + * + * @static + * @memberOf _ + * @alias object + * @category Arrays + * @param {Array} keys The array of keys. + * @param {Array} [values=[]] The array of values. + * @returns {Object} Returns an object composed of the given keys and + * corresponding values. + * @example + * + * _.zipObject(['moe', 'larry'], [30, 40]); + * // => { 'moe': 30, 'larry': 40 } + */ + function zipObject(keys, values) { + var index = -1, + length = keys ? keys.length : 0, + result = {}; + + while (++index < length) { + var key = keys[index]; + if (values) { + result[key] = values[index]; + } else { + result[key[0]] = key[1]; + } + } + return result; + } + /*--------------------------------------------------------------------------*/ /** @@ -4153,7 +4154,6 @@ lodash.max = max; lodash.memoize = memoize; lodash.min = min; - lodash.object = object; lodash.omit = omit; lodash.once = once; lodash.pairs = pairs; @@ -4183,6 +4183,7 @@ lodash.each = forEach; lodash.extend = assign; lodash.methods = functions; + lodash.object = zipObject; lodash.select = filter; lodash.tail = rest; lodash.unique = uniq; diff --git a/dist/lodash.underscore.min.js b/dist/lodash.underscore.min.js index 6c768309b..b256ae325 100644 --- a/dist/lodash.underscore.min.js +++ b/dist/lodash.underscore.min.js @@ -21,11 +21,11 @@ e.templateSettings={escape:/<%-([\s\S]+?)%>/g,evaluate:/<%([\s\S]+?)%>/g,interpo }},e.bind=U,e.bindAll=function(n){for(var r=mr.apply(vr,arguments),t=1T(e,o,t)&&u.push(o)}return u},e.filter=S,e.flatten=I,e.forEach=k,e.functions=y,e.groupBy=function(n,r,t){var e={}; return r=i(r,t),k(n,function(n,t,u){t=r(n,t,u)+"",(br.call(e,t)?e[t]:e[t]=[]).push(n)}),e},e.initial=function(n,r,t){if(!n)return[];var e=0,u=n.length;if(typeof r!="number"&&r!=H){var o=u;for(r=i(r,t);o--&&r(n[o],o,n);)e++}else e=r==H||t?1:r||e;return l(n,0,Fr(kr(0,u-e),u))},e.intersection=function(n){var r=arguments,t=r.length,e=-1,u=n?n.length:0,o=[];n:for(;++eT(o,i)){for(var a=t;--a;)if(0>T(r[a],i))continue n;o.push(i)}}return o},e.invert=_,e.invoke=function(n,r){var t=l(arguments,2),e=-1,u=typeof r=="function",o=n?n.length:0,i=Array(typeof o=="number"?o:0); -return k(n,function(n){i[++e]=(u?r:n[r]).apply(n,t)}),i},e.keys=$r,e.map=F,e.max=R,e.memoize=function(n,r){var t={};return function(){var e=(r?r.apply(this,arguments):arguments[0])+"";return br.call(t,e)?t[e]:t[e]=n.apply(this,arguments)}},e.min=function(n,r,e){var u=1/0,o=u;if(!r&&Mr(n)){e=-1;for(var a=n.length;++eT(t,r,1)&&(e[r]=n)}),e},e.once=function(n){var r,t;return function(){return r?t:(r=G,t=n.apply(this,arguments),n=H,t)}},e.pairs=function(n){for(var r=-1,t=$r(n),e=t.length,u=Array(e);++rT(arguments,u,1)&&e.push(u)}return e},e.wrap=function(n,r){return function(){var t=[n];return jr.apply(t,arguments),r.apply(this,t)}},e.zip=function(n){for(var r=-1,t=n?R(zr(arguments,"length")):0,e=Array(t);++rT(t,r,1)&&(e[r]=n) +}),e},e.once=function(n){var r,t;return function(){return r?t:(r=G,t=n.apply(this,arguments),n=H,t)}},e.pairs=function(n){for(var r=-1,t=$r(n),e=t.length,u=Array(e);++rT(arguments,u,1)&&e.push(u)}return e},e.wrap=function(n,r){return function(){var t=[n]; +return jr.apply(t,arguments),r.apply(this,t)}},e.zip=function(n){for(var r=-1,t=n?R(zr(arguments,"length")):0,e=Array(t);++rt?kr(0,e+t):Fr(t,e-1))+1);e--;)if(n[e]===r)return e;return-1},e.mixin=W,e.noConflict=function(){return n._=hr,this},e.random=function(n,r){return n==H&&r==H&&(r=1),n=+n||0,r==H&&(r=n,n=0),n+dr(Rr()*((+r||0)-n+1))},e.reduce=q,e.reduceRight=B,e.result=function(n,r){var t=n?n[r]:H;return b(t)?n[r]():t},e.size=function(n){var r=n?n.length:0;return typeof r=="number"?r:$r(n).length },e.some=D,e.sortedIndex=C,e.template=function(n,r,t){n||(n=""),t=g({},t,e.templateSettings);var u=0,o="__p+='",i=t.variable;n.replace(RegExp((t.escape||nr).source+"|"+(t.interpolate||nr).source+"|"+(t.evaluate||nr).source+"|$","g"),function(r,t,e,i,f){return o+=n.slice(u,f).replace(tr,a),t&&(o+="'+_['escape']("+t+")+'"),i&&(o+="';"+i+";__p+='"),e&&(o+="'+((__t=("+e+"))==null?'':__t)+'"),u=f+r.length,r}),o+="';\n",i||(i="obj",o="with("+i+"||{}){"+o+"}"),o="function("+i+"){var __t,__p='',__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}"+o+"return __p}"; diff --git a/doc/README.md b/doc/README.md index 8de3faab9..9c6a97403 100644 --- a/doc/README.md +++ b/doc/README.md @@ -17,7 +17,7 @@ * [`_.intersection`](#_intersectionarray1-array2-) * [`_.last`](#_lastarray--callbackn-thisarg) * [`_.lastIndexOf`](#_lastindexofarray-value--fromindexarraylength-1) -* [`_.object`](#_objectkeys--values) +* [`_.object`](#_zipobjectkeys--values) * [`_.range`](#_rangestart0-end--step1) * [`_.rest`](#_restarray--callbackn1-thisarg) * [`_.sortedIndex`](#_sortedindexarray-value--callbackidentity-thisarg) @@ -28,6 +28,7 @@ * [`_.unique`](#_uniqarray--issortedfalse-callbackidentity-thisarg) * [`_.without`](#_withoutarray--value1-value2-) * [`_.zip`](#_ziparray1-array2-) +* [`_.zipObject`](#_zipobjectkeys--values) @@ -532,35 +533,10 @@ _.lastIndexOf([1, 2, 3, 1, 2, 3], 2, 3); - - -### `_.object(keys [, values=[]])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3687 "View in source") [Ⓣ][1] - -Creates an object composed from arrays of `keys` and `values`. Pass either a single two dimensional array, i.e. `[[key1, value1], [key2, value2]]`, or two arrays, one of `keys` and one of corresponding `values`. - -#### Arguments -1. `keys` *(Array)*: The array of keys. -2. `[values=[]]` *(Array)*: The array of values. - -#### Returns -*(Object)*: Returns an object composed of the given keys and corresponding values. - -#### Example -```js -_.object(['moe', 'larry'], [30, 40]); -// => { 'moe': 30, 'larry': 40 } -``` - -* * * - - - - ### `_.range([start=0], end [, step=1])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3731 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3698 "View in source") [Ⓣ][1] Creates an array of numbers *(positive and/or negative)* progressing from `start` up to but not including `end`. @@ -598,7 +574,7 @@ _.range(0); ### `_.rest(array [, callback|n=1, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3810 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3777 "View in source") [Ⓣ][1] The opposite of `_.initial`, this method gets all but the first value of `array`. If a number `n` is passed, the first `n` values are excluded from the result. If a `callback` function is passed, elements at the beginning of the array are excluded from the result as long as the `callback` returns truthy. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index, array)*. @@ -658,7 +634,7 @@ _.rest(food, { 'type': 'fruit' }); ### `_.sortedIndex(array, value [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3874 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3841 "View in source") [Ⓣ][1] Uses a binary search to determine the smallest index at which the `value` should be inserted into `array` in order to maintain the sort order of the sorted `array`. If `callback` is passed, it will be executed for `value` and each element in `array` to compute their sort ranking. The `callback` is bound to `thisArg` and invoked with one argument; *(value)*. @@ -707,7 +683,7 @@ _.sortedIndex(['twenty', 'thirty', 'fifty'], 'fourty', function(word) { ### `_.union([array1, array2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3906 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3873 "View in source") [Ⓣ][1] Computes the union of the passed-in arrays using strict equality for comparisons, i.e. `===`. @@ -731,7 +707,7 @@ _.union([1, 2, 3], [101, 2, 1, 10], [2, 1]); ### `_.uniq(array [, isSorted=false, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3953 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3920 "View in source") [Ⓣ][1] Creates a duplicate-value-free version of the `array` using strict equality for comparisons, i.e. `===`. If the `array` is already sorted, passing `true` for `isSorted` will run a faster algorithm. If `callback` is passed, each element of `array` is passed through a callback` before uniqueness is computed. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index, array)*. @@ -778,7 +754,7 @@ _.uniq([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x'); ### `_.without(array [, value1, value2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4012 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3979 "View in source") [Ⓣ][1] Creates an array with all occurrences of the passed values removed using strict equality for comparisons, i.e. `===`. @@ -803,7 +779,7 @@ _.without([1, 2, 1, 0, 3, 1, 4], 0, 1); ### `_.zip([array1, array2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4043 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4010 "View in source") [Ⓣ][1] Groups the elements of each array at their corresponding indexes. Useful for separate data sources that are coordinated through matching array indexes. For a matrix of nested arrays, `_.zip.apply(...)` can transpose the matrix in a similar fashion. @@ -824,6 +800,34 @@ _.zip(['moe', 'larry'], [30, 40], [true, false]); + + +### `_.zipObject(keys [, values=[]])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4039 "View in source") [Ⓣ][1] + +Creates an object composed from arrays of `keys` and `values`. Pass either a single two dimensional array, i.e. `[[key1, value1], [key2, value2]]`, or two arrays, one of `keys` and one of corresponding `values`. + +#### Aliases +*object* + +#### Arguments +1. `keys` *(Array)*: The array of keys. +2. `[values=[]]` *(Array)*: The array of values. + +#### Returns +*(Object)*: Returns an object composed of the given keys and corresponding values. + +#### Example +```js +_.zipObject(['moe', 'larry'], [30, 40]); +// => { 'moe': 30, 'larry': 40 } +``` + +* * * + + + + @@ -865,7 +869,7 @@ The wrapper functions `first` and `last` return wrapped values when `n` is passe ### `_.tap(value, interceptor)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4941 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4942 "View in source") [Ⓣ][1] Invokes `interceptor` with the `value` as the first argument, and then returns `value`. The purpose of this method is to "tap into" a method chain, in order to perform operations on intermediate results within the chain. @@ -895,7 +899,7 @@ _([1, 2, 3, 4]) ### `_.prototype.toString()` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4958 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4959 "View in source") [Ⓣ][1] Produces the `toString` result of the wrapped value. @@ -916,7 +920,7 @@ _([1, 2, 3]).toString(); ### `_.prototype.valueOf()` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4975 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4976 "View in source") [Ⓣ][1] Extracts the wrapped value. @@ -1756,7 +1760,7 @@ _.where(stooges, { 'age': 40 }); ### `_.after(n, func)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4076 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4077 "View in source") [Ⓣ][1] Creates a function that is restricted to executing `func` only after it is called `n` times. The `func` is executed with the `this` binding of the created function. @@ -1784,7 +1788,7 @@ _.forEach(notes, function(note) { ### `_.bind(func [, thisArg, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4109 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4110 "View in source") [Ⓣ][1] Creates a function that, when called, invokes `func` with the `this` binding of `thisArg` and prepends any additional `bind` arguments to those passed to the bound function. @@ -1815,7 +1819,7 @@ func(); ### `_.bindAll(object [, methodName1, methodName2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4140 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4141 "View in source") [Ⓣ][1] Binds methods on `object` to `object`, overwriting the existing method. Method names may be specified as individual arguments or as arrays of method names. If no method names are provided, all the function properties of `object` will be bound. @@ -1846,7 +1850,7 @@ jQuery('#docs').on('click', view.onClick); ### `_.bindKey(object, key [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4186 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4187 "View in source") [Ⓣ][1] Creates a function that, when called, invokes the method at `object[key]` and prepends any additional `bindKey` arguments to those passed to the bound function. This method differs from `_.bind` by allowing bound functions to reference methods that will be redefined or don't yet exist. See http://michaux.ca/articles/lazy-function-definition-pattern. @@ -1887,7 +1891,7 @@ func(); ### `_.compose([func1, func2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4209 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4210 "View in source") [Ⓣ][1] Creates a function that is the composition of the passed functions, where each function consumes the return value of the function that follows. For example, composing the functions `f()`, `g()`, and `h()` produces `f(g(h()))`. Each function is executed with the `this` binding of the composed function. @@ -1914,7 +1918,7 @@ welcome('moe'); ### `_.debounce(func, wait, immediate)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4242 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4243 "View in source") [Ⓣ][1] Creates a function that will delay the execution of `func` until after `wait` milliseconds have elapsed since the last time it was invoked. Pass `true` for `immediate` to cause debounce to invoke `func` on the leading, instead of the trailing, edge of the `wait` timeout. Subsequent calls to the debounced function will return the result of the last `func` call. @@ -1940,7 +1944,7 @@ jQuery(window).on('resize', lazyLayout); ### `_.defer(func [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4306 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4307 "View in source") [Ⓣ][1] Defers executing the `func` function until the current call stack has cleared. Additional arguments will be passed to `func` when it is invoked. @@ -1965,7 +1969,7 @@ _.defer(function() { alert('deferred'); }); ### `_.delay(func, wait [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4286 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4287 "View in source") [Ⓣ][1] Executes the `func` function after `wait` milliseconds. Additional arguments will be passed to `func` when it is invoked. @@ -1992,7 +1996,7 @@ _.delay(log, 1000, 'logged later'); ### `_.memoize(func [, resolver])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4334 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4335 "View in source") [Ⓣ][1] Creates a function that memoizes the result of `func`. If `resolver` is passed, it will be used to determine the cache key for storing the result based on the arguments passed to the memoized function. By default, the first argument passed to the memoized function is used as the cache key. The `func` is executed with the `this` binding of the memoized function. @@ -2018,7 +2022,7 @@ var fibonacci = _.memoize(function(n) { ### `_.once(func)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4361 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4362 "View in source") [Ⓣ][1] Creates a function that is restricted to execute `func` once. Repeat calls to the function will return the value of the first call. The `func` is executed with the `this` binding of the created function. @@ -2044,7 +2048,7 @@ initialize(); ### `_.partial(func [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4396 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4397 "View in source") [Ⓣ][1] Creates a function that, when called, invokes `func` with any additional `partial` arguments prepended to those passed to the new function. This method is similar to `_.bind`, except it does **not** alter the `this` binding. @@ -2071,7 +2075,7 @@ hi('moe'); ### `_.partialRight(func [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4427 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4428 "View in source") [Ⓣ][1] This method is similar to `_.partial`, except that `partial` arguments are appended to those passed to the new function. @@ -2108,7 +2112,7 @@ options.imports ### `_.throttle(func, wait)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4449 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4450 "View in source") [Ⓣ][1] Creates a function that, when executed, will only call the `func` function at most once per every `wait` milliseconds. If the throttled function is invoked more than once during the `wait` timeout, `func` will also be called on the trailing edge of the timeout. Subsequent calls to the throttled function will return the result of the last `func` call. @@ -2133,7 +2137,7 @@ jQuery(window).on('scroll', throttled); ### `_.wrap(value, wrapper)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4502 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4503 "View in source") [Ⓣ][1] Creates a function that passes `value` to the `wrapper` function as its first argument. Additional arguments passed to the function are appended to those passed to the `wrapper` function. The `wrapper` is executed with the `this` binding of the created function. @@ -3175,7 +3179,7 @@ _.values({ 'one': 1, 'two': 2, 'three': 3 }); ### `_.escape(string)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4526 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4527 "View in source") [Ⓣ][1] Converts the characters `&`, `<`, `>`, `"`, and `'` in `string` to their corresponding HTML entities. @@ -3199,7 +3203,7 @@ _.escape('Moe, Larry & Curly'); ### `_.identity(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4544 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4545 "View in source") [Ⓣ][1] This function returns the first argument passed to it. @@ -3224,7 +3228,7 @@ moe === _.identity(moe); ### `_.mixin(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4570 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4571 "View in source") [Ⓣ][1] Adds functions properties of `object` to the `lodash` function and chainable wrapper. @@ -3254,7 +3258,7 @@ _('moe').capitalize(); ### `_.noConflict()` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4594 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4595 "View in source") [Ⓣ][1] Reverts the '_' variable to its previous value and returns a reference to the `lodash` function. @@ -3274,7 +3278,7 @@ var lodash = _.noConflict(); ### `_.random([min=0, max=1])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4617 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4618 "View in source") [Ⓣ][1] Produces a random number between `min` and `max` *(inclusive)*. If only one argument is passed, a number between `0` and the given number will be returned. @@ -3302,7 +3306,7 @@ _.random(5); ### `_.result(object, property)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4655 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4656 "View in source") [Ⓣ][1] Resolves the value of `property` on `object`. If `property` is a function, it will be invoked and its result returned, else the property value is returned. If `object` is falsey, then `null` is returned. @@ -3355,7 +3359,7 @@ Create a new `lodash` function using the given `context` object. ### `_.template(text, data, options)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4742 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4743 "View in source") [Ⓣ][1] A micro-templating method that handles arbitrary delimiters, preserves whitespace, and correctly escapes quotes within interpolated code. @@ -3439,7 +3443,7 @@ fs.writeFileSync(path.join(cwd, 'jst.js'), '\ ### `_.times(n, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4867 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4868 "View in source") [Ⓣ][1] Executes the `callback` function `n` times, returning an array of the results of each `callback` execution. The `callback` is bound to `thisArg` and invoked with one argument; *(index)*. @@ -3471,7 +3475,7 @@ _.times(3, function(n) { this.cast(n); }, mage); ### `_.unescape(string)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4893 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4894 "View in source") [Ⓣ][1] The opposite of `_.escape`, this method converts the HTML entities `&`, `<`, `>`, `"`, and `'` in `string` to their corresponding characters. @@ -3495,7 +3499,7 @@ _.unescape('Moe, Larry & Curly'); ### `_.uniqueId([prefix])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4913 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4914 "View in source") [Ⓣ][1] Generates a unique ID. If `prefix` is passed, the ID will be appended to it. @@ -3548,7 +3552,7 @@ A reference to the `lodash` function. ### `_.VERSION` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L5145 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L5147 "View in source") [Ⓣ][1] *(String)*: The semantic version number. diff --git a/lodash.js b/lodash.js index 2d198428e..ca8c88cc9 100644 --- a/lodash.js +++ b/lodash.js @@ -705,12 +705,12 @@ }; } if (argCount === 4) { - return function(accumulator, value, index, object) { - return func.call(thisArg, accumulator, value, index, object); + return function(accumulator, value, index, collection) { + return func.call(thisArg, accumulator, value, index, collection); }; } - return function(value, index, object) { - return func.call(thisArg, value, index, object); + return function(value, index, collection) { + return func.call(thisArg, value, index, collection); }; } return func; @@ -3667,39 +3667,6 @@ return -1; } - /** - * Creates an object composed from arrays of `keys` and `values`. Pass either - * a single two dimensional array, i.e. `[[key1, value1], [key2, value2]]`, or - * two arrays, one of `keys` and one of corresponding `values`. - * - * @static - * @memberOf _ - * @category Arrays - * @param {Array} keys The array of keys. - * @param {Array} [values=[]] The array of values. - * @returns {Object} Returns an object composed of the given keys and - * corresponding values. - * @example - * - * _.object(['moe', 'larry'], [30, 40]); - * // => { 'moe': 30, 'larry': 40 } - */ - function object(keys, values) { - var index = -1, - length = keys ? keys.length : 0, - result = {}; - - while (++index < length) { - var key = keys[index]; - if (values) { - result[key] = values[index]; - } else { - result[key[0]] = key[1]; - } - } - return result; - } - /** * Creates an array of numbers (positive and/or negative) progressing from * `start` up to but not including `end`. @@ -4051,6 +4018,40 @@ return result; } + /** + * Creates an object composed from arrays of `keys` and `values`. Pass either + * a single two dimensional array, i.e. `[[key1, value1], [key2, value2]]`, or + * two arrays, one of `keys` and one of corresponding `values`. + * + * @static + * @memberOf _ + * @alias object + * @category Arrays + * @param {Array} keys The array of keys. + * @param {Array} [values=[]] The array of values. + * @returns {Object} Returns an object composed of the given keys and + * corresponding values. + * @example + * + * _.zipObject(['moe', 'larry'], [30, 40]); + * // => { 'moe': 30, 'larry': 40 } + */ + function zipObject(keys, values) { + var index = -1, + length = keys ? keys.length : 0, + result = {}; + + while (++index < length) { + var key = keys[index]; + if (values) { + result[key] = values[index]; + } else { + result[key[0]] = key[1]; + } + } + return result; + } + /*--------------------------------------------------------------------------*/ /** @@ -5010,7 +5011,6 @@ lodash.memoize = memoize; lodash.merge = merge; lodash.min = min; - lodash.object = object; lodash.omit = omit; lodash.once = once; lodash.pairs = pairs; @@ -5034,6 +5034,7 @@ lodash.without = without; lodash.wrap = wrap; lodash.zip = zip; + lodash.zipObject = zipObject; // add aliases lodash.collect = map; @@ -5041,6 +5042,7 @@ lodash.each = forEach; lodash.extend = assign; lodash.methods = functions; + lodash.object = zipObject; lodash.select = filter; lodash.tail = rest; lodash.unique = uniq; diff --git a/test/test-build.js b/test/test-build.js index fa59c7db2..6d24e210e 100644 --- a/test/test-build.js +++ b/test/test-build.js @@ -60,6 +60,7 @@ 'include': 'contains', 'inject': 'reduce', 'methods': 'functions', + 'object': 'zipObject', 'select': 'filter', 'tail': 'rest', 'take': 'first', @@ -81,7 +82,8 @@ 'reduceRight': ['foldr'], 'rest': ['drop', 'tail'], 'some': ['any'], - 'uniq': ['unique'] + 'uniq': ['unique'], + 'zipObject': ['object'] }; /** List of all Lo-Dash methods */ @@ -113,7 +115,8 @@ 'uniq', 'unique', 'without', - 'zip' + 'zip', + 'zipObject' ]; /** List of "Chaining" category methods */ @@ -935,7 +938,8 @@ 'merge', 'parseInt', 'partialRight', - 'runInContext' + 'runInContext', + 'zipObject' ], function(methodName) { equal(lodash[methodName], undefined, '_.' + methodName + ' should not exist: ' + basename); });