From 33e5d46c87cb67c5c220bfce6cb31acae2c687ab Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Thu, 21 Nov 2013 09:31:55 -0800 Subject: [PATCH] Add `_.constant`, `_.mapValues`, and `_.xor`. --- dist/lodash.compat.js | 174 ++++++++++--- dist/lodash.compat.min.js | 53 ++-- dist/lodash.js | 174 ++++++++++--- dist/lodash.min.js | 77 +++--- dist/lodash.underscore.js | 55 +++-- dist/lodash.underscore.min.js | 18 +- doc/README.md | 447 +++++++++++++++++++++------------- lodash.js | 174 ++++++++++--- test/test.js | 161 ++++++++++-- 9 files changed, 939 insertions(+), 394 deletions(-) diff --git a/dist/lodash.compat.js b/dist/lodash.compat.js index 5a1aacef3..5bd7e874a 100644 --- a/dist/lodash.compat.js +++ b/dist/lodash.compat.js @@ -2483,15 +2483,15 @@ * @memberOf _ * @category Objects * @param {Object} object The object to inspect. - * @param {string} prop The name of the property to check. + * @param {string} key The name of the property to check. * @returns {boolean} Returns `true` if key is a direct property, else `false`. * @example * * _.has({ 'a': 1, 'b': 2, 'c': 3 }, 'b'); * // => true */ - function has(object, prop) { - return object ? hasOwnProperty.call(object, prop) : false; + function has(object, key) { + return object ? hasOwnProperty.call(object, key) : false; } /** @@ -2896,6 +2896,52 @@ return typeof value == 'undefined'; } + /** + * Creates an object with the same keys as `object` and values generated by + * running each own enumerable property of `object` through the callback. + * The callback is bound to `thisArg` and invoked with three arguments; + * (value, key, object). + * + * If a property name is provided for `callback` the created "_.pluck" style + * callback will return the property value of the given element. + * + * If an object is provided for `callback` the created "_.where" style callback + * will return `true` for elements that have the properties of the given object, + * else `false`. + * + * @static + * @memberOf _ + * @category Objects + * @param {Object} object The object to iterate over. + * @param {Function|Object|string} [callback=identity] The function called + * per iteration. If a property name or object is provided it will be used + * to create a "_.pluck" or "_.where" style callback, respectively. + * @param {*} [thisArg] The `this` binding of `callback`. + * @returns {Array} Returns a new object with values of the results of each `callback` execution. + * @example + * + * _.mapValues({ 'a': 1, 'b': 2, 'c': 3} , function(num) { return num * 3; }); + * // => { 'a': 3, 'b': 6, 'c': 9 } + * + * var characters = { + * 'fred': { 'name': 'fred', 'age': 40 }, + * 'pebbles': { 'name': 'pebbles', 'age': 1 } + * }; + * + * // using "_.pluck" callback shorthand + * _.mapValues(characters, 'age'); + * // => { 'fred': 40, 'pebbles': 1 } + */ + function mapValues(object, callback, thisArg) { + var result = {}; + callback = lodash.createCallback(callback, thisArg, 3); + + forOwn(object, function(value, key, object) { + result[key] = callback(value, key, object); + }); + return result; + } + /** * Recursively merges own enumerable properties of the source object(s), that * don't resolve to `undefined` into the destination object. Subsequent sources @@ -3111,11 +3157,11 @@ /** * An alternative to `_.reduce` this method transforms `object` to a new - * `accumulator` object which is the result of running each of its elements - * through a callback, with each callback execution potentially mutating - * the `accumulator` object. The callback is bound to `thisArg` and invoked - * with four arguments; (accumulator, value, key, object). Callbacks may exit - * iteration early by explicitly returning `false`. + * `accumulator` object which is the result of running each of its own + * enumerable properties through a callback, with each callback execution + * potentially mutating the `accumulator` object. The callback is bound to + * `thisArg` and invoked with four arguments; (accumulator, value, key, object). + * Callbacks may exit iteration early by explicitly returning `false`. * * @static * @memberOf _ @@ -4740,29 +4786,34 @@ * @memberOf _ * @category Arrays * @param {...Array} [array] The arrays to inspect. - * @returns {Array} Returns an array of composite values. + * @returns {Array} Returns an array of shared values. * @example * - * _.intersection([1, 2, 3], [101, 2, 1, 10], [2, 1]); + * _.intersection([1, 2, 3], [5, 2, 1, 4], [2, 1]); * // => [1, 2] */ - function intersection(array) { - var args = arguments, - argsLength = args.length, + function intersection() { + var args = [], argsIndex = -1, + argsLength = arguments.length, caches = getArray(), - index = -1, indexOf = getIndexOf(), - length = array ? array.length : 0, - result = [], + trustIndexOf = indexOf === baseIndexOf, seen = getArray(); while (++argsIndex < argsLength) { - var value = args[argsIndex]; - caches[argsIndex] = indexOf === baseIndexOf && - (value ? value.length : 0) >= largeArraySize && - createCache(argsIndex ? args[argsIndex] : seen); + var value = arguments[argsIndex]; + if (isArray(value) || isArguments(value)) { + args.push(value); + caches.push(trustIndexOf && value.length >= largeArraySize && + createCache(argsIndex ? args[argsIndex] : seen)); + } } + var array = args[0], + index = -1, + length = array ? array.length : 0, + result = []; + outer: while (++index < length) { var cache = caches[0]; @@ -5179,13 +5230,13 @@ * @memberOf _ * @category Arrays * @param {...Array} [array] The arrays to inspect. - * @returns {Array} Returns an array of composite values. + * @returns {Array} Returns an array of combined values. * @example * - * _.union([1, 2, 3], [101, 2, 1, 10], [2, 1]); - * // => [1, 2, 3, 101, 10] + * _.union([1, 2, 3], [5, 2, 1, 4], [2, 1]); + * // => [1, 2, 3, 5, 4] */ - function union(array) { + function union() { return baseUniq(baseFlatten(arguments, true, true)); } @@ -5265,6 +5316,37 @@ return baseDifference(array, slice(arguments, 1)); } + /** + * Creates an array that is the smymetric difference of the provided arrays. + * See http://en.wikipedia.org/wiki/Symmetric_difference. + * + * @static + * @memberOf _ + * @category Arrays + * @param {...Array} [array] The arrays to inspect. + * @returns {Array} Returns an array of values. + * @example + * + * _.xor([1, 2, 3], [5, 2, 1, 4]); + * // => [3, 5, 4] + * + * _.xor([1, 2, 5], [2, 3, 5], [3, 4, 5]); + * // => [1, 4, 5] + */ + function xor() { + var index = 0, + length = arguments.length, + result = arguments[0] || []; + + while (++index < length) { + var array = arguments[index]; + if (isArray(array) || isArguments(array)) { + result = baseUniq(baseDifference(result, array).concat(baseDifference(array, result))); + } + } + return result; + } + /** * Creates an array of grouped elements, the first of which contains the first * elements of the given arrays, the second of which contains the second @@ -5971,6 +6053,27 @@ /*--------------------------------------------------------------------------*/ + /** + * Creates a function that returns `value`. + * + * @static + * @memberOf _ + * @category Utilities + * @param {*} value The value to return from the new function. + * @returns {Function} Returns the new function. + * @example + * + * var object = { 'name': 'fred' }; + * var getter = _.constant(object); + * getter() === object; + * // => true + */ + function constant(value) { + return function() { + return value; + }; + } + /** * Produces a callback bound to an optional `thisArg`. If `func` is a property * name the created callback will return the property value for a given element. @@ -6200,14 +6303,14 @@ }; /** - * Creates a "_.pluck" style function, which returns the `prop` value of a + * Creates a "_.pluck" style function, which returns the `key` value of a * given object. * * @static * @memberOf _ * @category Utilities - * @param {string} prop The name of the property to retrieve. - * @returns {*} Returns the new function. + * @param {string} key The name of the property to retrieve. + * @returns {Function} Returns the new function. * @example * * var characters = [ @@ -6223,9 +6326,9 @@ * _.sortBy(characters, getName); * // => [{ 'name': 'barney', 'age': 36 }, { 'name': 'fred', 'age': 40 }] */ - function property(prop) { + function property(key) { return function(object) { - return object[prop]; + return object[key]; }; } @@ -6288,7 +6391,7 @@ } /** - * Resolves the value of `prop` on `object`. If `prop` is a function + * Resolves the value of property `key` on `object`. If `key` is a function * it will be invoked with the `this` binding of `object` and its result returned, * else the property value is returned. If `object` is falsey then `undefined` * is returned. @@ -6297,7 +6400,7 @@ * @memberOf _ * @category Utilities * @param {Object} object The object to inspect. - * @param {string} prop The name of the property to resolve. + * @param {string} key The name of the property to resolve. * @returns {*} Returns the resolved value. * @example * @@ -6314,10 +6417,10 @@ * _.result(object, 'stuff'); * // => 'nonsense' */ - function result(object, prop) { + function result(object, key) { if (object) { - var value = object[prop]; - return isFunction(value) ? object[prop]() : value; + var value = object[key]; + return isFunction(value) ? object[key]() : value; } } @@ -6714,6 +6817,7 @@ lodash.chain = chain; lodash.compact = compact; lodash.compose = compose; + lodash.constant = constant; lodash.countBy = countBy; lodash.create = create; lodash.createCallback = createCallback; @@ -6740,6 +6844,7 @@ lodash.invoke = invoke; lodash.keys = keys; lodash.map = map; + lodash.mapValues = mapValues; lodash.max = max; lodash.memoize = memoize; lodash.merge = merge; @@ -6770,6 +6875,7 @@ lodash.where = where; lodash.without = without; lodash.wrap = wrap; + lodash.xor = xor; lodash.zip = zip; lodash.zipObject = zipObject; diff --git a/dist/lodash.compat.min.js b/dist/lodash.compat.min.js index 849d9dd2b..03576cdc2 100644 --- a/dist/lodash.compat.min.js +++ b/dist/lodash.compat.min.js @@ -6,9 +6,9 @@ ;(function(){function n(n,t,e){e=(e||0)-1;for(var r=n?n.length:0;++er||typeof e=="undefined")return 1;if(ee?0:e);++r=_&&a===n,f=[];if(l){var c=o(r);c?(a=t,r=c):l=false}for(;++ua(r,c)&&f.push(c);return l&&p(r),f}function it(n,t,e,r){r=(r||0)-1;for(var u=n?n.length:0,o=[];++rk;k++)r+="n='"+e.h[k]+"';if((!(r&&x[n])&&m.call(t,n))",e.j||(r+="||(!x[n]&&t[n]!==A[n])"),r+="){"+e.g+"}";r+="}"}return(e.b||qe.nonEnumArgs)&&(r+="}"),r+=e.c+";return E",n("d,j,k,m,o,p,q,s,v,A,B,y,I,J,L",t+r+"}")(tt,q,se,xe,d,bt,We,Et,Q.f,ge,X,ze,M,he,ye) -}function vt(n){return Ve[n]}function yt(){var t=(t=v.indexOf)===qt?n:t;return t}function mt(n){var t,e;return!n||ye.call(n)!=G||(t=n.constructor,xt(t)&&!(t instanceof t))||!qe.argsClass&&bt(n)||!qe.nodeClass&&f(n)?false:qe.ownLast?(er(n,function(n,t,r){return e=xe.call(r,t),false}),false!==e):(er(n,function(n,t){e=t}),typeof e=="undefined"||xe.call(n,e))}function dt(n){return Qe[n]}function bt(n){return n&&typeof n=="object"&&typeof n.length=="number"&&ye.call(n)==$||false}function _t(n,t,e){var r=Je(n),u=r.length; +}function vt(n){return Ue[n]}function yt(){var t=(t=v.indexOf)===qt?n:t;return t}function mt(n){var t,e;return!n||ye.call(n)!=G||(t=n.constructor,xt(t)&&!(t instanceof t))||!qe.argsClass&&bt(n)||!qe.nodeClass&&f(n)?false:qe.ownLast?(er(n,function(n,t,r){return e=xe.call(r,t),false}),false!==e):(er(n,function(n,t){e=t}),typeof e=="undefined"||xe.call(n,e))}function dt(n){return Qe[n]}function bt(n){return n&&typeof n=="object"&&typeof n.length=="number"&&ye.call(n)==$||false}function _t(n,t,e){var r=Je(n),u=r.length; for(t=tt(t,e,3);u--&&(e=r[u],false!==t(n[e],e,n)););return n}function wt(n){var t=[];return er(n,function(n,e){xt(n)&&t.push(e)}),t.sort()}function jt(n){for(var t=-1,e=Je(n),r=e.length,u={};++te?Re(0,o+e):e)||0,We(n)?a=-1arguments.length;if(t=v.createCallback(t,r,4),We(n)){var o=-1,a=n.length;for(u&&(e=n[++o]);++oarguments.length;return t=v.createCallback(t,r,4),Bt(n,function(n,r,o){e=u?(u=false,n):t(e,n,r,o)}),e}function Tt(n){var t=-1,e=n?n.length:0,r=te(typeof e=="number"?e:0);return Nt(n,function(n){var e=ct(0,++t);r[t]=r[e],r[e]=n}),r}function Lt(n,t,e){var r;if(t=v.createCallback(t,e,3),We(n)){e=-1; for(var u=n.length;++er?Re(0,u+r):r||0}else if(r)return r=Wt(t,e),t[r]===e?r:-1;return n(t,e,r)}function Kt(n,t,e){if(typeof t!="number"&&null!=t){var r=0,u=-1,o=n?n.length:0; for(t=v.createCallback(t,e,3);++u>>1,e(n[r])e?0:e);++t=h;m?(a&&(a=be(a)),s=l,i=n.apply(f,o)):a||(a=Ee(r,h))}return m&&c?c=be(c):c||t===g||(c=Ee(u,t)),e&&(m=true,i=n.apply(f,o)),!m||c||a||(o=f=null),i}}function Vt(n){if(!xt(n))throw new ce;var t=s(arguments,1);return Ee(function(){n.apply(h,t)},1)}function Qt(n){return n +return r}function Mt(n,t){var e=-1,r=n?n.length:0,u={};for(t||!r||We(n[0])||(t=[]);++e=h;m?(a&&(a=be(a)),s=l,i=n.apply(f,o)):a||(a=Ee(r,h))}return m&&c?c=be(c):c||t===g||(c=Ee(u,t)),e&&(m=true,i=n.apply(f,o)),!m||c||a||(o=f=null),i}}function Ut(n){if(!xt(n))throw new ce;var t=s(arguments,1);return Ee(function(){n.apply(h,t)},1)}function Qt(n){return n }function Xt(n,t){var e=n,r=!t||xt(e);t||(e=y,t=n,n=v),Nt(wt(t),function(u){var o=n[u]=t[u];r&&(e.prototype[u]=function(){var t=this.__wrapped__,r=[t];return Ce.apply(r,arguments),r=o.apply(n,r),t&&typeof t=="object"&&t===r?this:(r=new e(r),r.__chain__=this.__chain__,r)})})}function Yt(){}function Zt(n){return function(t){return t[n]}}function ne(){return this.__wrapped__}e=e?ut.defaults(Z.Object(),e,ut.pick(Z,R)):Z;var te=e.Array,ee=e.Boolean,re=e.Date,ue=e.Function,oe=e.Math,ae=e.Number,ie=e.Object,le=e.RegExp,fe=e.String,ce=e.TypeError,pe=[],se=e.Error.prototype,ge=ie.prototype,he=fe.prototype,ve=e._,ye=ge.toString,me=le("^"+fe(ye).replace(/[.*+?^${}()|[\]\\]/g,"\\$&").replace(/toString| for [^\]]+/g,".*?")+"$"),de=oe.ceil,be=e.clearTimeout,_e=oe.floor,we=ue.prototype.toString,je=me.test(je=ie.getPrototypeOf)&&je,xe=ge.hasOwnProperty,Ce=pe.push,ke=ge.propertyIsEnumerable,Ee=e.setTimeout,Oe=pe.splice,Se=typeof(Se=rt&&et&&rt.setImmediate)=="function"&&!me.test(Se)&&Se,Ie=function(){try{var n={},t=me.test(t=ie.defineProperty)&&t,e=t(n,n,n)&&t }catch(r){}return e}(),Ae=me.test(Ae=ie.create)&&Ae,De=me.test(De=te.isArray)&&De,Ne=e.isFinite,Be=e.isNaN,Pe=me.test(Pe=ie.keys)&&Pe,Re=oe.max,Fe=oe.min,$e=e.parseInt,Te=oe.random,Le={};Le[T]=te,Le[L]=ee,Le[z]=re,Le[K]=ue,Le[G]=ie,Le[W]=ae,Le[J]=le,Le[M]=fe;var ze={};ze[T]=ze[z]=ze[W]={constructor:true,toLocaleString:true,toString:true,valueOf:true},ze[L]=ze[M]={constructor:true,toString:true,valueOf:true},ze[q]=ze[K]=ze[J]={constructor:true,toString:true},ze[G]={constructor:true},function(){for(var n=F.length;n--;){var t,e=F[n]; for(t in ze)xe.call(ze,t)&&!xe.call(ze[t],e)&&(ze[t][e]=false)}}(),y.prototype=v.prototype;var qe=v.support={};!function(){function n(){this.x=1}var t={0:1,length:1},r=[];n.prototype={valueOf:1,y:1};for(var u in new n)r.push(u);for(u in arguments);qe.argsClass=ye.call(arguments)==$,qe.argsObject=arguments.constructor==ie&&!(arguments instanceof te),qe.enumErrorProps=ke.call(se,"message")||ke.call(se,"name"),qe.enumPrototypes=ke.call(n,"prototype"),qe.funcDecomp=!me.test(e.p)&&B.test(g),qe.funcNames=typeof ue.name=="string",qe.nonEnumArgs=0!=u,qe.nonEnumShadows=!/valueOf/.test(r),qe.ownLast="x"!=r[0],qe.spliceObjects=(pe.splice.call(t,0,1),!t[0]),qe.unindexedChars="xx"!="x"[0]+ie("x")[0]; -try{qe.nodeClass=!(ye.call(document)==G&&!({toString:0}+""))}catch(o){qe.nodeClass=true}}(1),v.templateSettings={escape:/<%-([\s\S]+?)%>/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:A,variable:"",imports:{_:v}},Ae||(nt=function(){function n(){}return function(t){if(Ct(t)){n.prototype=t;var r=new n;n.prototype=null}return r||e.Object()}}());var Ke=Ie?function(n,t){V.value=t,Ie(n,"__bindData__",V)}:Yt;qe.argsClass||(bt=function(n){return n&&typeof n=="object"&&typeof n.length=="number"&&xe.call(n,"callee")&&!ke.call(n,"callee")||false -});var We=De||function(n){return n&&typeof n=="object"&&typeof n.length=="number"&&ye.call(n)==T||false},Ge=ht({a:"z",e:"[]",i:"if(!(B[typeof z]))return E",g:"E.push(n)"}),Je=Pe?function(n){return Ct(n)?qe.enumPrototypes&&typeof n=="function"||qe.nonEnumArgs&&n.length&&bt(n)?Ge(n):Pe(n):[]}:Ge,Me={a:"g,e,K",i:"e=e&&typeof K=='undefined'?e:d(e,K,3)",b:"typeof u=='number'",v:Je,g:"if(e(t[n],n,g)===false)return E"},He={a:"z,H,l",i:"var a=arguments,b=0,c=typeof l=='number'?2:a.length;while(++b":">",'"':""","'":"'"},Qe=jt(Ve),Xe=le("("+Je(Qe).join("|")+")","g"),Ye=le("["+Je(Ve).join("")+"]","g"),Ze=ht(Me),nr=ht(He,{i:He.i.replace(";",";if(c>3&&typeof a[c-2]=='function'){var e=d(a[--c-1],a[c--],2)}else if(c>2&&typeof a[c-1]=='function'){e=a[--c]}"),g:"E[n]=e?e(E[n],t[n]):t[n]"}),tr=ht(He),er=ht(Me,Ue,{j:false}),rr=ht(Me,Ue); -xt(/x/)&&(xt=function(n){return typeof n=="function"&&ye.call(n)==K});var ur=je?function(n){if(!n||ye.call(n)!=G||!qe.argsClass&&bt(n))return false;var t=n.valueOf,e=typeof t=="function"&&(e=je(t))&&je(e);return e?n==e||je(n)==e:mt(n)}:mt,or=st(function(n,t,e){xe.call(n,e)?n[e]++:n[e]=1}),ar=st(function(n,t,e){(xe.call(n,e)?n[e]:n[e]=[]).push(t)}),ir=st(function(n,t,e){n[e]=t}),lr=Pt;Se&&(Vt=function(n){if(!xt(n))throw new ce;return Se.apply(e,arguments)});var fr=me.test(fr=re.now)&&fr||function(){return(new re).getTime() -},cr=8==$e(j+"08")?$e:function(n,t){return $e(Et(n)?n.replace(D,""):n,t||0)};return v.after=function(n,t){if(!xt(t))throw new ce;return function(){return 1>--n?t.apply(this,arguments):void 0}},v.assign=nr,v.at=function(n){var t=arguments,e=-1,r=it(t,true,false,1),t=t[2]&&t[2][t[1]]===n?1:r.length,u=te(t);for(qe.unindexedChars&&Et(n)&&(n=n.split(""));++e/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:A,variable:"",imports:{_:v}},Ae||(nt=function(){function n(){}return function(t){if(Ct(t)){n.prototype=t;var r=new n;n.prototype=null}return r||e.Object()}}());var Ke=Ie?function(n,t){U.value=t,Ie(n,"__bindData__",U)}:Yt;qe.argsClass||(bt=function(n){return n&&typeof n=="object"&&typeof n.length=="number"&&xe.call(n,"callee")&&!ke.call(n,"callee")||false +});var We=De||function(n){return n&&typeof n=="object"&&typeof n.length=="number"&&ye.call(n)==T||false},Ge=ht({a:"z",e:"[]",i:"if(!(B[typeof z]))return E",g:"E.push(n)"}),Je=Pe?function(n){return Ct(n)?qe.enumPrototypes&&typeof n=="function"||qe.nonEnumArgs&&n.length&&bt(n)?Ge(n):Pe(n):[]}:Ge,Me={a:"g,e,K",i:"e=e&&typeof K=='undefined'?e:d(e,K,3)",b:"typeof u=='number'",v:Je,g:"if(e(t[n],n,g)===false)return E"},Ve={a:"z,H,l",i:"var a=arguments,b=0,c=typeof l=='number'?2:a.length;while(++b":">",'"':""","'":"'"},Qe=jt(Ue),Xe=le("("+Je(Qe).join("|")+")","g"),Ye=le("["+Je(Ue).join("")+"]","g"),Ze=ht(Me),nr=ht(Ve,{i:Ve.i.replace(";",";if(c>3&&typeof a[c-2]=='function'){var e=d(a[--c-1],a[c--],2)}else if(c>2&&typeof a[c-1]=='function'){e=a[--c]}"),g:"E[n]=e?e(E[n],t[n]):t[n]"}),tr=ht(Ve),er=ht(Me,He,{j:false}),rr=ht(Me,He); +xt(/x/)&&(xt=function(n){return typeof n=="function"&&ye.call(n)==K});var ur=je?function(n){if(!n||ye.call(n)!=G||!qe.argsClass&&bt(n))return false;var t=n.valueOf,e=typeof t=="function"&&(e=je(t))&&je(e);return e?n==e||je(n)==e:mt(n)}:mt,or=st(function(n,t,e){xe.call(n,e)?n[e]++:n[e]=1}),ar=st(function(n,t,e){(xe.call(n,e)?n[e]:n[e]=[]).push(t)}),ir=st(function(n,t,e){n[e]=t}),lr=Pt;Se&&(Ut=function(n){if(!xt(n))throw new ce;return Se.apply(e,arguments)});var fr=me.test(fr=re.now)&&fr||function(){return(new re).getTime() +},cr=8==$e(j+"08")?$e:function(n,t){return $e(Et(n)?n.replace(D,""):n,t||0)};return v.after=function(n,t){if(!xt(t))throw new ce;return function(){return 1>--n?t.apply(this,arguments):void 0}},v.assign=nr,v.at=function(n){var t=arguments,e=-1,r=it(t,true,false,1),t=t[2]&&t[2][t[1]]===n?1:r.length,u=te(t);for(qe.unindexedChars&&Et(n)&&(n=n.split(""));++e=_&&o(a?r[a]:v)}n:for(;++f(m?t(m,y):s(v,y))){for(a=u,(m||v).push(y);--a;)if(m=l[a],0>(m?t(m,y):s(r[a],y)))continue n;h.push(y)}}for(;u--;)(m=l[u])&&p(m);return c(l),c(v),h},v.invert=jt,v.invoke=function(n,t){var e=s(arguments,2),r=-1,u=typeof t=="function",o=n?n.length:0,a=te(typeof o=="number"?o:0); -return Nt(n,function(n){a[++r]=(u?t:n[t]).apply(n,e)}),a},v.keys=Je,v.map=Pt,v.max=Rt,v.memoize=function(n,t){function e(){var r=e.cache,u=t?t.apply(this,arguments):b+arguments[0];return xe.call(r,u)?r[u]:r[u]=n.apply(this,arguments)}if(!xt(n))throw new ce;return e.cache={},e},v.merge=function(n){var t=arguments,e=2;if(!Ct(n))return n;if("number"!=typeof t[2]&&(e=t.length),3e?Re(0,r+e):Fe(e,r-1))+1);r--;)if(n[r]===t)return r;return-1},v.mixin=Xt,v.noConflict=function(){return e._=ve,this},v.noop=Yt,v.now=fr,v.parseInt=cr,v.random=function(n,t,e){var r=null==n,u=null==t;return null==e&&(typeof n=="boolean"&&u?(e=n,n=1):u||typeof t!="boolean"||(e=t,u=true)),r&&u&&(t=1),n=+n||0,u?(t=n,n=0):t=+t||0,e||n%1||t%1?(e=Te(),Fe(n+e*(t-n+parseFloat("1e-"+((e+"").length-1))),t)):ct(n,t) -},v.reduce=Ft,v.reduceRight=$t,v.result=function(n,t){if(n){var e=n[t];return xt(e)?n[t]():e}},v.runInContext=g,v.size=function(n){var t=n?n.length:0;return typeof t=="number"?t:Je(n).length},v.some=Lt,v.sortedIndex=Wt,v.template=function(n,t,e){var r=v.templateSettings;n=fe(n||""),e=tr({},e,r);var u,o=tr({},e.imports,r.imports),r=Je(o),o=Ot(o),i=0,l=e.interpolate||N,f="__p+='",l=le((e.escape||N).source+"|"+l.source+"|"+(l===A?O:N).source+"|"+(e.evaluate||N).source+"|$","g");n.replace(l,function(t,e,r,o,l,c){return r||(r=o),f+=n.slice(i,c).replace(P,a),e&&(f+="'+__e("+e+")+'"),l&&(u=true,f+="';"+l+";\n__p+='"),r&&(f+="'+((__t=("+r+"))==null?'':__t)+'"),i=c+t.length,t +if(typeof t!="number"&&null!=t){var o=u;for(t=v.createCallback(t,e,3);o--&&t(n[o],o,n);)r++}else r=null==t||e?1:t||r;return s(n,0,Fe(Re(0,u-r),u))},v.intersection=function(){for(var e=[],r=-1,u=arguments.length,a=i(),l=yt(),f=l===n,s=i();++r=_&&o(r?e[r]:s)))}var f=e[0],h=-1,v=f?f.length:0,y=[];n:for(;++h(m?t(m,g):l(s,g))){for(r=u,(m||s).push(g);--r;)if(m=a[r],0>(m?t(m,g):l(e[r],g)))continue n;y.push(g) +}}for(;u--;)(m=a[u])&&p(m);return c(a),c(s),y},v.invert=jt,v.invoke=function(n,t){var e=s(arguments,2),r=-1,u=typeof t=="function",o=n?n.length:0,a=te(typeof o=="number"?o:0);return Nt(n,function(n){a[++r]=(u?t:n[t]).apply(n,e)}),a},v.keys=Je,v.map=Pt,v.mapValues=function(n,t,e){var r={};return t=v.createCallback(t,e,3),rr(n,function(n,e,u){r[e]=t(n,e,u)}),r},v.max=Rt,v.memoize=function(n,t){function e(){var r=e.cache,u=t?t.apply(this,arguments):b+arguments[0];return xe.call(r,u)?r[u]:r[u]=n.apply(this,arguments) +}if(!xt(n))throw new ce;return e.cache={},e},v.merge=function(n){var t=arguments,e=2;if(!Ct(n))return n;if("number"!=typeof t[2]&&(e=t.length),3e?Re(0,r+e):Fe(e,r-1))+1);r--;)if(n[r]===t)return r; +return-1},v.mixin=Xt,v.noConflict=function(){return e._=ve,this},v.noop=Yt,v.now=fr,v.parseInt=cr,v.random=function(n,t,e){var r=null==n,u=null==t;return null==e&&(typeof n=="boolean"&&u?(e=n,n=1):u||typeof t!="boolean"||(e=t,u=true)),r&&u&&(t=1),n=+n||0,u?(t=n,n=0):t=+t||0,e||n%1||t%1?(e=Te(),Fe(n+e*(t-n+parseFloat("1e-"+((e+"").length-1))),t)):ct(n,t)},v.reduce=Ft,v.reduceRight=$t,v.result=function(n,t){if(n){var e=n[t];return xt(e)?n[t]():e}},v.runInContext=g,v.size=function(n){var t=n?n.length:0; +return typeof t=="number"?t:Je(n).length},v.some=Lt,v.sortedIndex=Wt,v.template=function(n,t,e){var r=v.templateSettings;n=fe(n||""),e=tr({},e,r);var u,o=tr({},e.imports,r.imports),r=Je(o),o=Ot(o),i=0,l=e.interpolate||N,f="__p+='",l=le((e.escape||N).source+"|"+l.source+"|"+(l===A?O:N).source+"|"+(e.evaluate||N).source+"|$","g");n.replace(l,function(t,e,r,o,l,c){return r||(r=o),f+=n.slice(i,c).replace(P,a),e&&(f+="'+__e("+e+")+'"),l&&(u=true,f+="';"+l+";\n__p+='"),r&&(f+="'+((__t=("+r+"))==null?'':__t)+'"),i=c+t.length,t }),f+="';",l=e=e.variable,l||(e="obj",f="with("+e+"){"+f+"}"),f=(u?f.replace(x,""):f).replace(C,"$1").replace(E,"$1;"),f="function("+e+"){"+(l?"":e+"||("+e+"={});")+"var __t,__p='',__e=_.escape"+(u?",__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}":";")+f+"return __p}";try{var c=ue(r,"return "+f).apply(h,o)}catch(p){throw p.source=f,p}return t?c(t):(c.source=f,c)},v.unescape=function(n){return null==n?"":fe(n).replace(Xe,dt)},v.uniqueId=function(n){var t=++m;return fe(null==n?"":n)+t },v.all=It,v.any=Lt,v.detect=Dt,v.findWhere=Dt,v.foldl=Ft,v.foldr=$t,v.include=St,v.inject=Ft,rr(v,function(n,t){v.prototype[t]||(v.prototype[t]=function(){var t=[this.__wrapped__],e=this.__chain__;return Ce.apply(t,arguments),t=n.apply(v,t),e?new y(t,e):t})}),v.first=zt,v.last=function(n,t,e){var r=0,u=n?n.length:0;if(typeof t!="number"&&null!=t){var o=u;for(t=v.createCallback(t,e,3);o--&&t(n[o],o,n);)r++}else if(r=t,null==r||e)return n?n[u-1]:h;return s(n,Re(0,u-r))},v.sample=function(n,t,e){return n&&typeof n.length!="number"?n=Ot(n):qe.unindexedChars&&Et(n)&&(n=n.split("")),null==t||e?n?n[ct(0,n.length-1)]:h:(n=Tt(n),n.length=Fe(Re(0,t),n.length),n) },v.take=zt,v.head=zt,rr(v,function(n,t){var e="sample"!==t;v.prototype[t]||(v.prototype[t]=function(t,r){var u=this.__chain__,o=n(this.__wrapped__,t,r);return u||null!=t&&(!r||e&&typeof t=="function")?new y(o,u):o})}),v.VERSION="2.3.0",v.prototype.chain=function(){return this.__chain__=true,this},v.prototype.toString=function(){return fe(this.__wrapped__)},v.prototype.value=ne,v.prototype.valueOf=ne,Ze(["join","pop","shift"],function(n){var t=pe[n];v.prototype[n]=function(){var n=this.__chain__,e=t.apply(this.__wrapped__,arguments); return n?new y(e,n):e}}),Ze(["push","reverse","sort","unshift"],function(n){var t=pe[n];v.prototype[n]=function(){return t.apply(this.__wrapped__,arguments),this}}),Ze(["concat","slice","splice"],function(n){var t=pe[n];v.prototype[n]=function(){return new y(t.apply(this.__wrapped__,arguments),this.__chain__)}}),qe.spliceObjects||Ze(["pop","shift","splice"],function(n){var t=pe[n],e="splice"==n;v.prototype[n]=function(){var n=this.__chain__,r=this.__wrapped__,u=t.apply(r,arguments);return 0===r.length&&delete r[0],n||e?new y(u,n):u -}}),v}var h,v=[],y=[],m=0,d={},b=+new Date+"",_=75,w=40,j=" \t\x0B\f\xa0\ufeff\n\r\u2028\u2029\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000",x=/\b__p\+='';/g,C=/\b(__p\+=)''\+/g,E=/(__e\(.*?\)|\b__t\))\+'';/g,O=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,S=/\w*$/,I=/^\s*function[ \n\r\t]+\w/,A=/<%=([\s\S]+?)%>/g,D=RegExp("^["+j+"]*0+(?=.$)"),N=/($^)/,B=/\bthis\b/,P=/['\n\r\t\u2028\u2029\\]/g,R="Array Boolean Date Error Function Math Number Object RegExp String _ attachEvent clearTimeout isFinite isNaN parseInt setImmediate setTimeout".split(" "),F="constructor hasOwnProperty isPrototypeOf propertyIsEnumerable toLocaleString toString valueOf".split(" "),$="[object Arguments]",T="[object Array]",L="[object Boolean]",z="[object Date]",q="[object Error]",K="[object Function]",W="[object Number]",G="[object Object]",J="[object RegExp]",M="[object String]",H={}; -H[K]=false,H[$]=H[T]=H[L]=H[z]=H[W]=H[G]=H[J]=H[M]=true;var U={leading:false,maxWait:0,trailing:false},V={configurable:false,enumerable:false,value:null,writable:false},Q={a:"",b:null,c:"",d:"",e:"",v:null,g:"",h:null,support:null,i:"",j:false},X={"boolean":false,"function":true,object:true,number:false,string:false,undefined:false},Y={"\\":"\\","'":"'","\n":"n","\r":"r","\t":"t","\u2028":"u2028","\u2029":"u2029"},Z=X[typeof window]&&window||this,nt=X[typeof exports]&&exports&&!exports.nodeType&&exports,tt=X[typeof module]&&module&&!module.nodeType&&module,et=tt&&tt.exports===nt&&nt,rt=X[typeof global]&&global; +}}),v}var h,v=[],y=[],m=0,d={},b=+new Date+"",_=75,w=40,j=" \t\x0B\f\xa0\ufeff\n\r\u2028\u2029\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000",x=/\b__p\+='';/g,C=/\b(__p\+=)''\+/g,E=/(__e\(.*?\)|\b__t\))\+'';/g,O=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,S=/\w*$/,I=/^\s*function[ \n\r\t]+\w/,A=/<%=([\s\S]+?)%>/g,D=RegExp("^["+j+"]*0+(?=.$)"),N=/($^)/,B=/\bthis\b/,P=/['\n\r\t\u2028\u2029\\]/g,R="Array Boolean Date Error Function Math Number Object RegExp String _ attachEvent clearTimeout isFinite isNaN parseInt setImmediate setTimeout".split(" "),F="constructor hasOwnProperty isPrototypeOf propertyIsEnumerable toLocaleString toString valueOf".split(" "),$="[object Arguments]",T="[object Array]",L="[object Boolean]",z="[object Date]",q="[object Error]",K="[object Function]",W="[object Number]",G="[object Object]",J="[object RegExp]",M="[object String]",V={}; +V[K]=false,V[$]=V[T]=V[L]=V[z]=V[W]=V[G]=V[J]=V[M]=true;var H={leading:false,maxWait:0,trailing:false},U={configurable:false,enumerable:false,value:null,writable:false},Q={a:"",b:null,c:"",d:"",e:"",v:null,g:"",h:null,support:null,i:"",j:false},X={"boolean":false,"function":true,object:true,number:false,string:false,undefined:false},Y={"\\":"\\","'":"'","\n":"n","\r":"r","\t":"t","\u2028":"u2028","\u2029":"u2029"},Z=X[typeof window]&&window||this,nt=X[typeof exports]&&exports&&!exports.nodeType&&exports,tt=X[typeof module]&&module&&!module.nodeType&&module,et=tt&&tt.exports===nt&&nt,rt=X[typeof global]&&global; !rt||rt.global!==rt&&rt.window!==rt||(Z=rt);var ut=g();typeof define=="function"&&typeof define.amd=="object"&&define.amd?(Z._=ut, define(function(){return ut})):nt&&tt?et?(tt.exports=ut)._=ut:nt._=ut:Z._=ut}).call(this); \ No newline at end of file diff --git a/dist/lodash.js b/dist/lodash.js index 48290238b..af48867e3 100644 --- a/dist/lodash.js +++ b/dist/lodash.js @@ -2150,15 +2150,15 @@ * @memberOf _ * @category Objects * @param {Object} object The object to inspect. - * @param {string} prop The name of the property to check. + * @param {string} key The name of the property to check. * @returns {boolean} Returns `true` if key is a direct property, else `false`. * @example * * _.has({ 'a': 1, 'b': 2, 'c': 3 }, 'b'); * // => true */ - function has(object, prop) { - return object ? hasOwnProperty.call(object, prop) : false; + function has(object, key) { + return object ? hasOwnProperty.call(object, key) : false; } /** @@ -2556,6 +2556,52 @@ return typeof value == 'undefined'; } + /** + * Creates an object with the same keys as `object` and values generated by + * running each own enumerable property of `object` through the callback. + * The callback is bound to `thisArg` and invoked with three arguments; + * (value, key, object). + * + * If a property name is provided for `callback` the created "_.pluck" style + * callback will return the property value of the given element. + * + * If an object is provided for `callback` the created "_.where" style callback + * will return `true` for elements that have the properties of the given object, + * else `false`. + * + * @static + * @memberOf _ + * @category Objects + * @param {Object} object The object to iterate over. + * @param {Function|Object|string} [callback=identity] The function called + * per iteration. If a property name or object is provided it will be used + * to create a "_.pluck" or "_.where" style callback, respectively. + * @param {*} [thisArg] The `this` binding of `callback`. + * @returns {Array} Returns a new object with values of the results of each `callback` execution. + * @example + * + * _.mapValues({ 'a': 1, 'b': 2, 'c': 3} , function(num) { return num * 3; }); + * // => { 'a': 3, 'b': 6, 'c': 9 } + * + * var characters = { + * 'fred': { 'name': 'fred', 'age': 40 }, + * 'pebbles': { 'name': 'pebbles', 'age': 1 } + * }; + * + * // using "_.pluck" callback shorthand + * _.mapValues(characters, 'age'); + * // => { 'fred': 40, 'pebbles': 1 } + */ + function mapValues(object, callback, thisArg) { + var result = {}; + callback = lodash.createCallback(callback, thisArg, 3); + + forOwn(object, function(value, key, object) { + result[key] = callback(value, key, object); + }); + return result; + } + /** * Recursively merges own enumerable properties of the source object(s), that * don't resolve to `undefined` into the destination object. Subsequent sources @@ -2771,11 +2817,11 @@ /** * An alternative to `_.reduce` this method transforms `object` to a new - * `accumulator` object which is the result of running each of its elements - * through a callback, with each callback execution potentially mutating - * the `accumulator` object. The callback is bound to `thisArg` and invoked - * with four arguments; (accumulator, value, key, object). Callbacks may exit - * iteration early by explicitly returning `false`. + * `accumulator` object which is the result of running each of its own + * enumerable properties through a callback, with each callback execution + * potentially mutating the `accumulator` object. The callback is bound to + * `thisArg` and invoked with four arguments; (accumulator, value, key, object). + * Callbacks may exit iteration early by explicitly returning `false`. * * @static * @memberOf _ @@ -4390,29 +4436,34 @@ * @memberOf _ * @category Arrays * @param {...Array} [array] The arrays to inspect. - * @returns {Array} Returns an array of composite values. + * @returns {Array} Returns an array of shared values. * @example * - * _.intersection([1, 2, 3], [101, 2, 1, 10], [2, 1]); + * _.intersection([1, 2, 3], [5, 2, 1, 4], [2, 1]); * // => [1, 2] */ - function intersection(array) { - var args = arguments, - argsLength = args.length, + function intersection() { + var args = [], argsIndex = -1, + argsLength = arguments.length, caches = getArray(), - index = -1, indexOf = getIndexOf(), - length = array ? array.length : 0, - result = [], + trustIndexOf = indexOf === baseIndexOf, seen = getArray(); while (++argsIndex < argsLength) { - var value = args[argsIndex]; - caches[argsIndex] = indexOf === baseIndexOf && - (value ? value.length : 0) >= largeArraySize && - createCache(argsIndex ? args[argsIndex] : seen); + var value = arguments[argsIndex]; + if (isArray(value) || isArguments(value)) { + args.push(value); + caches.push(trustIndexOf && value.length >= largeArraySize && + createCache(argsIndex ? args[argsIndex] : seen)); + } } + var array = args[0], + index = -1, + length = array ? array.length : 0, + result = []; + outer: while (++index < length) { var cache = caches[0]; @@ -4829,13 +4880,13 @@ * @memberOf _ * @category Arrays * @param {...Array} [array] The arrays to inspect. - * @returns {Array} Returns an array of composite values. + * @returns {Array} Returns an array of combined values. * @example * - * _.union([1, 2, 3], [101, 2, 1, 10], [2, 1]); - * // => [1, 2, 3, 101, 10] + * _.union([1, 2, 3], [5, 2, 1, 4], [2, 1]); + * // => [1, 2, 3, 5, 4] */ - function union(array) { + function union() { return baseUniq(baseFlatten(arguments, true, true)); } @@ -4915,6 +4966,37 @@ return baseDifference(array, slice(arguments, 1)); } + /** + * Creates an array that is the smymetric difference of the provided arrays. + * See http://en.wikipedia.org/wiki/Symmetric_difference. + * + * @static + * @memberOf _ + * @category Arrays + * @param {...Array} [array] The arrays to inspect. + * @returns {Array} Returns an array of values. + * @example + * + * _.xor([1, 2, 3], [5, 2, 1, 4]); + * // => [3, 5, 4] + * + * _.xor([1, 2, 5], [2, 3, 5], [3, 4, 5]); + * // => [1, 4, 5] + */ + function xor() { + var index = 0, + length = arguments.length, + result = arguments[0] || []; + + while (++index < length) { + var array = arguments[index]; + if (isArray(array) || isArguments(array)) { + result = baseUniq(baseDifference(result, array).concat(baseDifference(array, result))); + } + } + return result; + } + /** * Creates an array of grouped elements, the first of which contains the first * elements of the given arrays, the second of which contains the second @@ -5621,6 +5703,27 @@ /*--------------------------------------------------------------------------*/ + /** + * Creates a function that returns `value`. + * + * @static + * @memberOf _ + * @category Utilities + * @param {*} value The value to return from the new function. + * @returns {Function} Returns the new function. + * @example + * + * var object = { 'name': 'fred' }; + * var getter = _.constant(object); + * getter() === object; + * // => true + */ + function constant(value) { + return function() { + return value; + }; + } + /** * Produces a callback bound to an optional `thisArg`. If `func` is a property * name the created callback will return the property value for a given element. @@ -5850,14 +5953,14 @@ }; /** - * Creates a "_.pluck" style function, which returns the `prop` value of a + * Creates a "_.pluck" style function, which returns the `key` value of a * given object. * * @static * @memberOf _ * @category Utilities - * @param {string} prop The name of the property to retrieve. - * @returns {*} Returns the new function. + * @param {string} key The name of the property to retrieve. + * @returns {Function} Returns the new function. * @example * * var characters = [ @@ -5873,9 +5976,9 @@ * _.sortBy(characters, getName); * // => [{ 'name': 'barney', 'age': 36 }, { 'name': 'fred', 'age': 40 }] */ - function property(prop) { + function property(key) { return function(object) { - return object[prop]; + return object[key]; }; } @@ -5938,7 +6041,7 @@ } /** - * Resolves the value of `prop` on `object`. If `prop` is a function + * Resolves the value of property `key` on `object`. If `key` is a function * it will be invoked with the `this` binding of `object` and its result returned, * else the property value is returned. If `object` is falsey then `undefined` * is returned. @@ -5947,7 +6050,7 @@ * @memberOf _ * @category Utilities * @param {Object} object The object to inspect. - * @param {string} prop The name of the property to resolve. + * @param {string} key The name of the property to resolve. * @returns {*} Returns the resolved value. * @example * @@ -5964,10 +6067,10 @@ * _.result(object, 'stuff'); * // => 'nonsense' */ - function result(object, prop) { + function result(object, key) { if (object) { - var value = object[prop]; - return isFunction(value) ? object[prop]() : value; + var value = object[key]; + return isFunction(value) ? object[key]() : value; } } @@ -6364,6 +6467,7 @@ lodash.chain = chain; lodash.compact = compact; lodash.compose = compose; + lodash.constant = constant; lodash.countBy = countBy; lodash.create = create; lodash.createCallback = createCallback; @@ -6390,6 +6494,7 @@ lodash.invoke = invoke; lodash.keys = keys; lodash.map = map; + lodash.mapValues = mapValues; lodash.max = max; lodash.memoize = memoize; lodash.merge = merge; @@ -6420,6 +6525,7 @@ lodash.where = where; lodash.without = without; lodash.wrap = wrap; + lodash.xor = xor; lodash.zip = zip; lodash.zipObject = zipObject; diff --git a/dist/lodash.min.js b/dist/lodash.min.js index b0d87a85a..707c4e634 100644 --- a/dist/lodash.min.js +++ b/dist/lodash.min.js @@ -4,51 +4,52 @@ * Build: `lodash modern -o ./dist/lodash.js` */ ;(function(){function n(n,t,e){e=(e||0)-1;for(var r=n?n.length:0;++er||typeof e=="undefined")return 1;if(ee?0:e);++r=_&&i===n,l=[];if(f){var p=o(r);p?(i=t,r=p):f=false}for(;++ui(r,p)&&l.push(p);return f&&c(r),l}function at(n,t,e,r){r=(r||0)-1;for(var u=n?n.length:0,o=[];++r=_&&f===n,h=u||v?a():s; -if(v){var g=o(h);g?(f=t,h=g):(v=false,h=u?h:(l(h),s))}for(;++if(h,y))&&((u||v)&&h.push(y),s.push(g))}return v?(l(h.k),c(h)):u&&l(h),s}function st(n){return function(t,e,r){var u={};e=Z.createCallback(e,r,3),r=-1;var o=t?t.length:0;if(typeof o=="number")for(;++re?Re(0,o+e):e)||0,We(n)?i=-1r||typeof e=="undefined")return 1;if(ee?0:e);++r=_&&a===n,l=[];if(f){var p=o(r);p?(a=t,r=p):f=false}for(;++ua(r,p)&&l.push(p);return f&&c(r),l}function it(n,t,e,r){r=(r||0)-1;for(var u=n?n.length:0,o=[];++r=_&&f===n,h=u||v?i():s; +if(v){var g=o(h);g?(f=t,h=g):(v=false,h=u?h:(l(h),s))}for(;++af(h,y))&&((u||v)&&h.push(y),s.push(g))}return v?(l(h.k),c(h)):u&&l(h),s}function st(n){return function(t,e,r){var u={};e=Z.createCallback(e,r,3),r=-1;var o=t?t.length:0;if(typeof o=="number")for(;++re?Re(0,o+e):e)||0,We(n)?a=-1o&&(o=a)}}else t=null==t&&Ct(n)?r:Z.createCallback(t,e,3),Rt(n,function(n,e,r){e=t(n,e,r),e>u&&(u=e,o=n)});return o}function Tt(n,t,e,r){if(!n)return e;var u=3>arguments.length;t=Z.createCallback(t,r,4);var o=-1,i=n.length;if(typeof i=="number")for(u&&(e=n[++o]);++oarguments.length;return t=Z.createCallback(t,r,4),At(n,function(n,r,o){e=u?(u=false,n):t(e,n,r,o) +for(var a=n.length;++eo&&(o=i)}}else t=null==t&&Ct(n)?r:Z.createCallback(t,e,3),Rt(n,function(n,e,r){e=t(n,e,r),e>u&&(u=e,o=n)});return o}function Tt(n,t,e,r){if(!n)return e;var u=3>arguments.length;t=Z.createCallback(t,r,4);var o=-1,a=n.length;if(typeof a=="number")for(u&&(e=n[++o]);++oarguments.length;return t=Z.createCallback(t,r,4),At(n,function(n,r,o){e=u?(u=false,n):t(e,n,r,o) }),e}function Bt(n){var t=-1,e=n?n.length:0,r=ne(typeof e=="number"?e:0);return Rt(n,function(n){var e=ct(0,++t);r[t]=r[e],r[e]=n}),r}function Wt(n,t,e){var r;t=Z.createCallback(t,e,3),e=-1;var u=n?n.length:0;if(typeof u=="number")for(;++er?Re(0,u+r):r||0}else if(r)return r=Kt(t,e),t[r]===e?r:-1;return n(t,e,r)}function Pt(n,t,e){if(typeof t!="number"&&null!=t){var r=0,u=-1,o=n?n.length:0;for(t=Z.createCallback(t,e,3);++u>>1,e(n[r])e?0:e);++t=v;m?(i&&(i=ye(i)),s=f,a=n.apply(l,o)):i||(i=je(r,v))}return m&&c?c=ye(c):c||t===h||(c=je(u,t)),e&&(m=true,a=n.apply(l,o)),!m||c||i||(o=l=null),a}}function Ht(n){if(!jt(n))throw new le;var t=p(arguments,1); -return je(function(){n.apply(v,t)},1)}function Jt(n){return n}function Qt(n,t){var e=n,r=!t||jt(e);t||(e=nt,t=n,n=Z),Rt(dt(t),function(u){var o=n[u]=t[u];r&&(e.prototype[u]=function(){var t=this.__wrapped__,r=[t];return we.apply(r,arguments),r=o.apply(n,r),t&&typeof t=="object"&&t===r?this:(r=new e(r),r.__chain__=this.__chain__,r)})})}function Xt(){}function Yt(n){return function(t){return t[n]}}function Zt(){return this.__wrapped__}e=e?Y.defaults(G.Object(),e,Y.pick(G,A)):G;var ne=e.Array,te=e.Boolean,ee=e.Date,re=e.Function,ue=e.Math,oe=e.Number,ie=e.Object,ae=e.RegExp,fe=e.String,le=e.TypeError,ce=[],pe=ie.prototype,se=e._,ve=pe.toString,he=ae("^"+fe(ve).replace(/[.*+?^${}()|[\]\\]/g,"\\$&").replace(/toString| for [^\]]+/g,".*?")+"$"),ge=ue.ceil,ye=e.clearTimeout,me=ue.floor,_e=re.prototype.toString,be=he.test(be=ie.getPrototypeOf)&&be,de=pe.hasOwnProperty,we=ce.push,je=e.setTimeout,ke=ce.splice,xe=typeof(xe=X&&Q&&X.setImmediate)=="function"&&!he.test(xe)&&xe,Ce=function(){try{var n={},t=he.test(t=ie.defineProperty)&&t,e=t(n,n,n)&&t -}catch(r){}return e}(),Oe=he.test(Oe=ie.create)&&Oe,Ie=he.test(Ie=ne.isArray)&&Ie,Ne=e.isFinite,Se=e.isNaN,Ee=he.test(Ee=ie.keys)&&Ee,Re=ue.max,Ae=ue.min,De=e.parseInt,$e=ue.random,Te={};Te[$]=ne,Te[T]=te,Te[F]=ee,Te[B]=re,Te[q]=ie,Te[W]=oe,Te[z]=ae,Te[P]=fe,nt.prototype=Z.prototype;var Fe=Z.support={};Fe.funcDecomp=!he.test(e.a)&&E.test(s),Fe.funcNames=typeof re.name=="string",Z.templateSettings={escape:/<%-([\s\S]+?)%>/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:I,variable:"",imports:{_:Z}},Oe||(rt=function(){function n(){}return function(t){if(kt(t)){n.prototype=t; -var r=new n;n.prototype=null}return r||e.Object()}}());var Be=Ce?function(n,t){M.value=t,Ce(n,"__bindData__",M)}:Xt,We=Ie||function(n){return n&&typeof n=="object"&&typeof n.length=="number"&&ve.call(n)==$||false},qe=Ee?function(n){return kt(n)?Ee(n):[]}:J,ze={"&":"&","<":"<",">":">",'"':""","'":"'"},Pe=wt(ze),Ke=ae("("+qe(Pe).join("|")+")","g"),Le=ae("["+qe(ze).join("")+"]","g"),Me=st(function(n,t,e){de.call(n,e)?n[e]++:n[e]=1}),Ue=st(function(n,t,e){(de.call(n,e)?n[e]:n[e]=[]).push(t) -}),Ve=st(function(n,t,e){n[e]=t}),Ge=Dt;xe&&(Ht=function(n){if(!jt(n))throw new le;return xe.apply(e,arguments)});var He=he.test(He=ee.now)&&He||function(){return(new ee).getTime()},Je=8==De(d+"08")?De:function(n,t){return De(Ct(n)?n.replace(N,""):n,t||0)};return Z.after=function(n,t){if(!jt(t))throw new le;return function(){return 1>--n?t.apply(this,arguments):void 0}},Z.assign=H,Z.at=function(n){for(var t=arguments,e=-1,r=at(t,true,false,1),t=t[2]&&t[2][t[1]]===n?1:r.length,u=ne(t);++e=_&&o(i?r[i]:g)}n:for(;++p(m?t(m,y):s(g,y))){for(i=u,(m||g).push(y);--i;)if(m=f[i],0>(m?t(m,y):s(r[i],y)))continue n; -h.push(y)}}for(;u--;)(m=f[u])&&c(m);return l(f),l(g),h},Z.invert=wt,Z.invoke=function(n,t){var e=p(arguments,2),r=-1,u=typeof t=="function",o=n?n.length:0,i=ne(typeof o=="number"?o:0);return Rt(n,function(n){i[++r]=(u?t:n[t]).apply(n,e)}),i},Z.keys=qe,Z.map=Dt,Z.max=$t,Z.memoize=function(n,t){function e(){var r=e.cache,u=t?t.apply(this,arguments):m+arguments[0];return de.call(r,u)?r[u]:r[u]=n.apply(this,arguments)}if(!jt(n))throw new le;return e.cache={},e},Z.merge=function(n){var t=arguments,e=2; -if(!kt(n))return n;if("number"!=typeof t[2]&&(e=t.length),3e?0:e);++t=v;m?(a&&(a=ye(a)),s=f,i=n.apply(l,o)):a||(a=je(r,v))}return m&&c?c=ye(c):c||t===h||(c=je(u,t)),e&&(m=true,i=n.apply(l,o)),!m||c||a||(o=l=null),i}}function Ht(n){if(!jt(n))throw new le;var t=p(arguments,1); +return je(function(){n.apply(v,t)},1)}function Jt(n){return n}function Qt(n,t){var e=n,r=!t||jt(e);t||(e=nt,t=n,n=Z),Rt(dt(t),function(u){var o=n[u]=t[u];r&&(e.prototype[u]=function(){var t=this.__wrapped__,r=[t];return we.apply(r,arguments),r=o.apply(n,r),t&&typeof t=="object"&&t===r?this:(r=new e(r),r.__chain__=this.__chain__,r)})})}function Xt(){}function Yt(n){return function(t){return t[n]}}function Zt(){return this.__wrapped__}e=e?Y.defaults(G.Object(),e,Y.pick(G,A)):G;var ne=e.Array,te=e.Boolean,ee=e.Date,re=e.Function,ue=e.Math,oe=e.Number,ae=e.Object,ie=e.RegExp,fe=e.String,le=e.TypeError,ce=[],pe=ae.prototype,se=e._,ve=pe.toString,he=ie("^"+fe(ve).replace(/[.*+?^${}()|[\]\\]/g,"\\$&").replace(/toString| for [^\]]+/g,".*?")+"$"),ge=ue.ceil,ye=e.clearTimeout,me=ue.floor,_e=re.prototype.toString,be=he.test(be=ae.getPrototypeOf)&&be,de=pe.hasOwnProperty,we=ce.push,je=e.setTimeout,ke=ce.splice,xe=typeof(xe=X&&Q&&X.setImmediate)=="function"&&!he.test(xe)&&xe,Ce=function(){try{var n={},t=he.test(t=ae.defineProperty)&&t,e=t(n,n,n)&&t +}catch(r){}return e}(),Oe=he.test(Oe=ae.create)&&Oe,Ie=he.test(Ie=ne.isArray)&&Ie,Ne=e.isFinite,Se=e.isNaN,Ee=he.test(Ee=ae.keys)&&Ee,Re=ue.max,Ae=ue.min,De=e.parseInt,$e=ue.random,Te={};Te[$]=ne,Te[T]=te,Te[F]=ee,Te[B]=re,Te[q]=ae,Te[W]=oe,Te[z]=ie,Te[P]=fe,nt.prototype=Z.prototype;var Fe=Z.support={};Fe.funcDecomp=!he.test(e.a)&&E.test(s),Fe.funcNames=typeof re.name=="string",Z.templateSettings={escape:/<%-([\s\S]+?)%>/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:I,variable:"",imports:{_:Z}},Oe||(rt=function(){function n(){}return function(t){if(kt(t)){n.prototype=t; +var r=new n;n.prototype=null}return r||e.Object()}}());var Be=Ce?function(n,t){M.value=t,Ce(n,"__bindData__",M)}:Xt,We=Ie||function(n){return n&&typeof n=="object"&&typeof n.length=="number"&&ve.call(n)==$||false},qe=Ee?function(n){return kt(n)?Ee(n):[]}:J,ze={"&":"&","<":"<",">":">",'"':""","'":"'"},Pe=wt(ze),Ke=ie("("+qe(Pe).join("|")+")","g"),Le=ie("["+qe(ze).join("")+"]","g"),Me=st(function(n,t,e){de.call(n,e)?n[e]++:n[e]=1}),Ve=st(function(n,t,e){(de.call(n,e)?n[e]:n[e]=[]).push(t) +}),Ue=st(function(n,t,e){n[e]=t}),Ge=Dt;xe&&(Ht=function(n){if(!jt(n))throw new le;return xe.apply(e,arguments)});var He=he.test(He=ee.now)&&He||function(){return(new ee).getTime()},Je=8==De(d+"08")?De:function(n,t){return De(Ct(n)?n.replace(N,""):n,t||0)};return Z.after=function(n,t){if(!jt(t))throw new le;return function(){return 1>--n?t.apply(this,arguments):void 0}},Z.assign=H,Z.at=function(n){for(var t=arguments,e=-1,r=it(t,true,false,1),t=t[2]&&t[2][t[1]]===n?1:r.length,u=ne(t);++e=_&&o(r?e[r]:s))) +}var p=e[0],h=-1,g=p?p.length:0,y=[];n:for(;++h(m?t(m,v):f(s,v))){for(r=u,(m||s).push(v);--r;)if(m=a[r],0>(m?t(m,v):f(e[r],v)))continue n;y.push(v)}}for(;u--;)(m=a[u])&&c(m);return l(a),l(s),y},Z.invert=wt,Z.invoke=function(n,t){var e=p(arguments,2),r=-1,u=typeof t=="function",o=n?n.length:0,a=ne(typeof o=="number"?o:0);return Rt(n,function(n){a[++r]=(u?t:n[t]).apply(n,e)}),a},Z.keys=qe,Z.map=Dt,Z.mapValues=function(n,t,e){var r={};return t=Z.createCallback(t,e,3),g(n,function(n,e,u){r[e]=t(n,e,u) +}),r},Z.max=$t,Z.memoize=function(n,t){function e(){var r=e.cache,u=t?t.apply(this,arguments):m+arguments[0];return de.call(r,u)?r[u]:r[u]=n.apply(this,arguments)}if(!jt(n))throw new le;return e.cache={},e},Z.merge=function(n){var t=arguments,e=2;if(!kt(n))return n;if("number"!=typeof t[2]&&(e=t.length),3e?Re(0,r+e):Ae(e,r-1))+1);r--;)if(n[r]===t)return r;return-1},Z.mixin=Qt,Z.noConflict=function(){return e._=se,this},Z.noop=Xt,Z.now=He,Z.parseInt=Je,Z.random=function(n,t,e){var r=null==n,u=null==t;return null==e&&(typeof n=="boolean"&&u?(e=n,n=1):u||typeof t!="boolean"||(e=t,u=true)),r&&u&&(t=1),n=+n||0,u?(t=n,n=0):t=+t||0,e||n%1||t%1?(e=$e(),Ae(n+e*(t-n+parseFloat("1e-"+((e+"").length-1))),t)):ct(n,t) -},Z.reduce=Tt,Z.reduceRight=Ft,Z.result=function(n,t){if(n){var e=n[t];return jt(e)?n[t]():e}},Z.runInContext=s,Z.size=function(n){var t=n?n.length:0;return typeof t=="number"?t:qe(n).length},Z.some=Wt,Z.sortedIndex=Kt,Z.template=function(n,t,e){var r=Z.templateSettings;n=fe(n||""),e=V({},e,r);var u,o=V({},e.imports,r.imports),r=qe(o),o=Ot(o),a=0,f=e.interpolate||S,l="__p+='",f=ae((e.escape||S).source+"|"+f.source+"|"+(f===I?x:S).source+"|"+(e.evaluate||S).source+"|$","g");n.replace(f,function(t,e,r,o,f,c){return r||(r=o),l+=n.slice(a,c).replace(R,i),e&&(l+="'+__e("+e+")+'"),f&&(u=true,l+="';"+f+";\n__p+='"),r&&(l+="'+((__t=("+r+"))==null?'':__t)+'"),a=c+t.length,t +},Z.reduce=Tt,Z.reduceRight=Ft,Z.result=function(n,t){if(n){var e=n[t];return jt(e)?n[t]():e}},Z.runInContext=s,Z.size=function(n){var t=n?n.length:0;return typeof t=="number"?t:qe(n).length},Z.some=Wt,Z.sortedIndex=Kt,Z.template=function(n,t,e){var r=Z.templateSettings;n=fe(n||""),e=U({},e,r);var u,o=U({},e.imports,r.imports),r=qe(o),o=Ot(o),i=0,f=e.interpolate||S,l="__p+='",f=ie((e.escape||S).source+"|"+f.source+"|"+(f===I?x:S).source+"|"+(e.evaluate||S).source+"|$","g");n.replace(f,function(t,e,r,o,f,c){return r||(r=o),l+=n.slice(i,c).replace(R,a),e&&(l+="'+__e("+e+")+'"),f&&(u=true,l+="';"+f+";\n__p+='"),r&&(l+="'+((__t=("+r+"))==null?'':__t)+'"),i=c+t.length,t }),l+="';",f=e=e.variable,f||(e="obj",l="with("+e+"){"+l+"}"),l=(u?l.replace(w,""):l).replace(j,"$1").replace(k,"$1;"),l="function("+e+"){"+(f?"":e+"||("+e+"={});")+"var __t,__p='',__e=_.escape"+(u?",__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}":";")+l+"return __p}";try{var c=re(r,"return "+l).apply(v,o)}catch(p){throw p.source=l,p}return t?c(t):(c.source=l,c)},Z.unescape=function(n){return null==n?"":fe(n).replace(Ke,mt)},Z.uniqueId=function(n){var t=++y;return fe(null==n?"":n)+t },Z.all=Nt,Z.any=Wt,Z.detect=Et,Z.findWhere=Et,Z.foldl=Tt,Z.foldr=Ft,Z.include=It,Z.inject=Tt,g(Z,function(n,t){Z.prototype[t]||(Z.prototype[t]=function(){var t=[this.__wrapped__],e=this.__chain__;return we.apply(t,arguments),t=n.apply(Z,t),e?new nt(t,e):t})}),Z.first=qt,Z.last=function(n,t,e){var r=0,u=n?n.length:0;if(typeof t!="number"&&null!=t){var o=u;for(t=Z.createCallback(t,e,3);o--&&t(n[o],o,n);)r++}else if(r=t,null==r||e)return n?n[u-1]:v;return p(n,Re(0,u-r))},Z.sample=function(n,t,e){return n&&typeof n.length!="number"&&(n=Ot(n)),null==t||e?n?n[ct(0,n.length-1)]:v:(n=Bt(n),n.length=Ae(Re(0,t),n.length),n) },Z.take=qt,Z.head=qt,g(Z,function(n,t){var e="sample"!==t;Z.prototype[t]||(Z.prototype[t]=function(t,r){var u=this.__chain__,o=n(this.__wrapped__,t,r);return u||null!=t&&(!r||e&&typeof t=="function")?new nt(o,u):o})}),Z.VERSION="2.3.0",Z.prototype.chain=function(){return this.__chain__=true,this},Z.prototype.toString=function(){return fe(this.__wrapped__)},Z.prototype.value=Zt,Z.prototype.valueOf=Zt,Rt(["join","pop","shift"],function(n){var t=ce[n];Z.prototype[n]=function(){var n=this.__chain__,e=t.apply(this.__wrapped__,arguments); return n?new nt(e,n):e}}),Rt(["push","reverse","sort","unshift"],function(n){var t=ce[n];Z.prototype[n]=function(){return t.apply(this.__wrapped__,arguments),this}}),Rt(["concat","slice","splice"],function(n){var t=ce[n];Z.prototype[n]=function(){return new nt(t.apply(this.__wrapped__,arguments),this.__chain__)}}),Z}var v,h=[],g=[],y=0,m=+new Date+"",_=75,b=40,d=" \t\x0B\f\xa0\ufeff\n\r\u2028\u2029\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000",w=/\b__p\+='';/g,j=/\b(__p\+=)''\+/g,k=/(__e\(.*?\)|\b__t\))\+'';/g,x=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,C=/\w*$/,O=/^\s*function[ \n\r\t]+\w/,I=/<%=([\s\S]+?)%>/g,N=RegExp("^["+d+"]*0+(?=.$)"),S=/($^)/,E=/\bthis\b/,R=/['\n\r\t\u2028\u2029\\]/g,A="Array Boolean Date Function Math Number Object RegExp String _ attachEvent clearTimeout isFinite isNaN parseInt setImmediate setTimeout".split(" "),D="[object Arguments]",$="[object Array]",T="[object Boolean]",F="[object Date]",B="[object Function]",W="[object Number]",q="[object Object]",z="[object RegExp]",P="[object String]",K={}; -K[B]=false,K[D]=K[$]=K[T]=K[F]=K[W]=K[q]=K[z]=K[P]=true;var L={leading:false,maxWait:0,trailing:false},M={configurable:false,enumerable:false,value:null,writable:false},U={"boolean":false,"function":true,object:true,number:false,string:false,undefined:false},V={"\\":"\\","'":"'","\n":"n","\r":"r","\t":"t","\u2028":"u2028","\u2029":"u2029"},G=U[typeof window]&&window||this,H=U[typeof exports]&&exports&&!exports.nodeType&&exports,J=U[typeof module]&&module&&!module.nodeType&&module,Q=J&&J.exports===H&&H,X=U[typeof global]&&global;!X||X.global!==X&&X.window!==X||(G=X); +K[B]=false,K[D]=K[$]=K[T]=K[F]=K[W]=K[q]=K[z]=K[P]=true;var L={leading:false,maxWait:0,trailing:false},M={configurable:false,enumerable:false,value:null,writable:false},V={"boolean":false,"function":true,object:true,number:false,string:false,undefined:false},U={"\\":"\\","'":"'","\n":"n","\r":"r","\t":"t","\u2028":"u2028","\u2029":"u2029"},G=V[typeof window]&&window||this,H=V[typeof exports]&&exports&&!exports.nodeType&&exports,J=V[typeof module]&&module&&!module.nodeType&&module,Q=J&&J.exports===H&&H,X=V[typeof global]&&global;!X||X.global!==X&&X.window!==X||(G=X); var Y=s();typeof define=="function"&&typeof define.amd=="object"&&define.amd?(G._=Y, define(function(){return Y})):H&&J?Q?(J.exports=Y)._=Y:H._=Y:G._=Y}).call(this); \ No newline at end of file diff --git a/dist/lodash.underscore.js b/dist/lodash.underscore.js index 86ccf3ff6..b1a8f86b4 100644 --- a/dist/lodash.underscore.js +++ b/dist/lodash.underscore.js @@ -1215,15 +1215,15 @@ * @memberOf _ * @category Objects * @param {Object} object The object to inspect. - * @param {string} prop The name of the property to check. + * @param {string} key The name of the property to check. * @returns {boolean} Returns `true` if key is a direct property, else `false`. * @example * * _.has({ 'a': 1, 'b': 2, 'c': 3 }, 'b'); * // => true */ - function has(object, prop) { - return object ? hasOwnProperty.call(object, prop) : false; + function has(object, key) { + return object ? hasOwnProperty.call(object, key) : false; } /** @@ -3108,15 +3108,24 @@ * @memberOf _ * @category Arrays * @param {...Array} [array] The arrays to inspect. - * @returns {Array} Returns an array of composite values. + * @returns {Array} Returns an array of shared values. * @example * - * _.intersection([1, 2, 3], [101, 2, 1, 10], [2, 1]); + * _.intersection([1, 2, 3], [5, 2, 1, 4], [2, 1]); * // => [1, 2] */ - function intersection(array) { - var args = arguments, - argsLength = args.length, + function intersection() { + var args = [], + argsIndex = -1, + argsLength = arguments.length; + + while (++argsIndex < argsLength) { + var value = arguments[argsIndex]; + if (isArray(value) || isArguments(value)) { + args.push(value); + } + } + var array = args[0], index = -1, indexOf = getIndexOf(), length = array ? array.length : 0, @@ -3124,7 +3133,7 @@ outer: while (++index < length) { - var value = array[index]; + value = array[index]; if (indexOf(result, value) < 0) { var argsIndex = argsLength; while (--argsIndex) { @@ -3441,13 +3450,13 @@ * @memberOf _ * @category Arrays * @param {...Array} [array] The arrays to inspect. - * @returns {Array} Returns an array of composite values. + * @returns {Array} Returns an array of combined values. * @example * - * _.union([1, 2, 3], [101, 2, 1, 10], [2, 1]); - * // => [1, 2, 3, 101, 10] + * _.union([1, 2, 3], [5, 2, 1, 4], [2, 1]); + * // => [1, 2, 3, 5, 4] */ - function union(array) { + function union() { return baseUniq(baseFlatten(arguments, true, true)); } @@ -4294,14 +4303,14 @@ }; /** - * Creates a "_.pluck" style function, which returns the `prop` value of a + * Creates a "_.pluck" style function, which returns the `key` value of a * given object. * * @static * @memberOf _ * @category Utilities - * @param {string} prop The name of the property to retrieve. - * @returns {*} Returns the new function. + * @param {string} key The name of the property to retrieve. + * @returns {Function} Returns the new function. * @example * * var characters = [ @@ -4317,9 +4326,9 @@ * _.sortBy(characters, getName); * // => [{ 'name': 'barney', 'age': 36 }, { 'name': 'fred', 'age': 40 }] */ - function property(prop) { + function property(key) { return function(object) { - return object[prop]; + return object[key]; }; } @@ -4365,7 +4374,7 @@ } /** - * Resolves the value of `prop` on `object`. If `prop` is a function + * Resolves the value of property `key` on `object`. If `key` is a function * it will be invoked with the `this` binding of `object` and its result returned, * else the property value is returned. If `object` is falsey then `undefined` * is returned. @@ -4374,7 +4383,7 @@ * @memberOf _ * @category Utilities * @param {Object} object The object to inspect. - * @param {string} prop The name of the property to resolve. + * @param {string} key The name of the property to resolve. * @returns {*} Returns the resolved value. * @example * @@ -4391,10 +4400,10 @@ * _.result(object, 'stuff'); * // => 'nonsense' */ - function result(object, prop) { + function result(object, key) { if (object) { - var value = object[prop]; - return isFunction(value) ? object[prop]() : value; + var value = object[key]; + return isFunction(value) ? object[key]() : value; } } diff --git a/dist/lodash.underscore.min.js b/dist/lodash.underscore.min.js index 070ba79d4..e4a46655c 100644 --- a/dist/lodash.underscore.min.js +++ b/dist/lodash.underscore.min.js @@ -25,15 +25,15 @@ Wr.spliceObjects=(wr.splice.call(n,0,1),!n[0])}(1),u.templateSettings={escape:/< },Cr=function(n){var r,t=[];if(!n||!hr[typeof n])return t;for(r in n)Sr.call(n,r)&&t.push(r);return t},Pr=Dr?function(n){return A(n)?Dr(n):[]}:Cr,Ur={"&":"&","<":"<",">":">",'"':""","'":"'"},Vr=x(Ur),Gr=RegExp("("+Pr(Vr).join("|")+")","g"),Hr=RegExp("["+Pr(Ur).join("")+"]","g"),Jr=function(n,r){var t;if(!n||!hr[typeof n])return n;for(t in n)if(r(n[t],t,n)===tr)break;return n},Kr=function(n,r){var t;if(!n||!hr[typeof n])return n;for(t in n)if(Sr.call(n,t)&&r(n[t],t,n)===tr)break; return n};E(/x/)&&(E=function(n){return typeof n=="function"&&"[object Function]"==Tr.call(n)});var Lr=h(function(n,r,t){Sr.call(n,t)?n[t]++:n[t]=1}),Qr=h(function(n,r,t){(Sr.call(n,t)?n[t]:n[t]=[]).push(r)}),Xr=h(function(n,r,t){n[t]=r}),Yr=I,Zr=Er.test(Zr=Date.now)&&Zr||function(){return(new Date).getTime()};u.after=function(n,r){if(!E(r))throw new TypeError;return function(){return 1>--n?r.apply(this,arguments):void 0}},u.bind=K,u.bindAll=function(n){for(var r=1u(i,f)){for(var a=t;--a;)if(0>u(r[a],f))continue n;i.push(f)}}return i},u.invert=x,u.invoke=function(n,r){var t=e(arguments,2),u=-1,o=typeof r=="function",i=n?n.length:0,f=Array(typeof i=="number"?i:0);return q(n,function(n){f[++u]=(o?r:n[r]).apply(n,t)}),f},u.keys=Pr,u.map=I,u.max=M,u.memoize=function(n,r){var t={};return function(){var e=r?r.apply(this,arguments):er+arguments[0];return Sr.call(t,e)?t[e]:t[e]=n.apply(this,arguments)}},u.min=function(n,r,t){var e=1/0,u=e; -typeof r!="function"&&t&&t[r]===n&&(r=null);var o=-1,i=n?n.length:0;if(null==r&&typeof i=="number")for(;++or?0:r);++nt?Ir(0,e+t):Mr(t,e-1))+1);e--;)if(n[e]===r)return e;return-1},u.mixin=Y,u.noConflict=function(){return yr._=xr,this},u.random=function(n,r){return null==n&&null==r&&(r=1),n=+n||0,null==r?(r=n,n=0):r=+r||0,n+Or($r()*(r-n+1)) -},u.reduce=$,u.reduceRight=W,u.result=function(n,r){if(n){var t=n[r];return E(t)?n[r]():t}},u.size=function(n){var r=n?n.length:0;return typeof r=="number"?r:Pr(n).length},u.some=C,u.sortedIndex=H,u.template=function(n,r,e){var o=u,i=o.templateSettings;n=(n||"")+"",e=w({},e,i);var f=0,a="__p+='",i=e.variable;n.replace(RegExp((e.escape||ur).source+"|"+(e.interpolate||ur).source+"|"+(e.evaluate||ur).source+"|$","g"),function(r,e,u,o,i){return a+=n.slice(f,i).replace(or,t),e&&(a+="'+_.escape("+e+")+'"),o&&(a+="';"+o+";\n__p+='"),u&&(a+="'+((__t=("+u+"))==null?'':__t)+'"),f=i+r.length,r +},1)},u.delay=function(n,r){if(!E(n))throw new TypeError;var t=e(arguments,2);return setTimeout(function(){n.apply(nr,t)},r)},u.difference=function(n){return c(n,p(arguments,true,true,1))},u.filter=B,u.flatten=function(n,r){return p(n,r)},u.forEach=q,u.functions=j,u.groupBy=Qr,u.indexBy=Xr,u.initial=function(n,r,t){var u=0,o=n?n.length:0;if(typeof r!="number"&&null!=r){var i=o;for(r=Q(r,t,3);i--&&r(n[i],i,n);)u++}else u=null==r||t?1:r||u;return e(n,0,Mr(Ir(0,o-u),o))},u.intersection=function(){for(var n=[],r=-1,t=arguments.length;++ri(a,e)){for(r=t;--r;)if(0>i(n[r],e))continue n;a.push(e)}return a},u.invert=x,u.invoke=function(n,r){var t=e(arguments,2),u=-1,o=typeof r=="function",i=n?n.length:0,f=Array(typeof i=="number"?i:0);return q(n,function(n){f[++u]=(o?r:n[r]).apply(n,t)}),f},u.keys=Pr,u.map=I,u.max=M,u.memoize=function(n,r){var t={};return function(){var e=r?r.apply(this,arguments):er+arguments[0];return Sr.call(t,e)?t[e]:t[e]=n.apply(this,arguments) +}},u.min=function(n,r,t){var e=1/0,u=e;typeof r!="function"&&t&&t[r]===n&&(r=null);var o=-1,i=n?n.length:0;if(null==r&&typeof i=="number")for(;++or?0:r);++nt?Ir(0,e+t):Mr(t,e-1))+1);e--;)if(n[e]===r)return e; +return-1},u.mixin=Y,u.noConflict=function(){return yr._=xr,this},u.random=function(n,r){return null==n&&null==r&&(r=1),n=+n||0,null==r?(r=n,n=0):r=+r||0,n+Or($r()*(r-n+1))},u.reduce=$,u.reduceRight=W,u.result=function(n,r){if(n){var t=n[r];return E(t)?n[r]():t}},u.size=function(n){var r=n?n.length:0;return typeof r=="number"?r:Pr(n).length},u.some=C,u.sortedIndex=H,u.template=function(n,r,e){var o=u,i=o.templateSettings;n=(n||"")+"",e=w({},e,i);var f=0,a="__p+='",i=e.variable;n.replace(RegExp((e.escape||ur).source+"|"+(e.interpolate||ur).source+"|"+(e.evaluate||ur).source+"|$","g"),function(r,e,u,o,i){return a+=n.slice(f,i).replace(or,t),e&&(a+="'+_.escape("+e+")+'"),o&&(a+="';"+o+";\n__p+='"),u&&(a+="'+((__t=("+u+"))==null?'':__t)+'"),f=i+r.length,r }),a+="';",i||(i="obj",a="with("+i+"||{}){"+a+"}"),a="function("+i+"){var __t,__p='',__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}"+a+"return __p}";try{var l=Function("_","return "+a)(o)}catch(c){throw c.source=a,c}return r?l(r):(l.source=a,l)},u.unescape=function(n){return null==n?"":(n+"").replace(Gr,_)},u.uniqueId=function(n){var r=++rr+"";return n?n+r:r},u.all=k,u.any=C,u.detect=F,u.findWhere=function(n,r){return P(n,r,true)},u.foldl=$,u.foldr=W,u.include=R,u.inject=$,u.first=U,u.last=function(n,r,t){var u=0,o=n?n.length:0; if(typeof r!="number"&&null!=r){var i=o;for(r=Q(r,t,3);i--&&r(n[i],i,n);)u++}else if(u=r,null==u||t)return n?n[o-1]:nr;return e(n,Ir(0,o-u))},u.sample=function(n,r,t){return n&&typeof n.length!="number"&&(n=N(n)),null==r||t?n?n[0+Or($r()*(n.length-1-0+1))]:nr:(n=z(n),n.length=Mr(Ir(0,r),n.length),n)},u.take=U,u.head=U,Y(u),u.VERSION="2.3.0",u.prototype.chain=function(){return this.__chain__=true,this},u.prototype.value=function(){return this.__wrapped__},q("pop push reverse shift sort splice unshift".split(" "),function(n){var r=wr[n]; u.prototype[n]=function(){var n=this.__wrapped__;return r.apply(n,arguments),Wr.spliceObjects||0!==n.length||delete n[0],this}}),q(["concat","join","slice"],function(n){var r=wr[n];u.prototype[n]=function(){var n=r.apply(this.__wrapped__,arguments);return this.__chain__&&(n=new o(n),n.__chain__=true),n}}),typeof define=="function"&&typeof define.amd=="object"&&define.amd?(yr._=u, define(function(){return u})):mr&&_r?dr?(_r.exports=u)._=u:mr._=u:yr._=u}).call(this); \ No newline at end of file diff --git a/doc/README.md b/doc/README.md index 0a0ed80ed..dc8523fae 100644 --- a/doc/README.md +++ b/doc/README.md @@ -32,6 +32,7 @@ * `_.unique -> uniq` * `_.unzip -> zip` * `_.without` +* `_.xor` * `_.zip` * `_.zipObject` @@ -105,7 +106,6 @@ * `_.bindAll` * `_.bindKey` * `_.compose` -* `_.createCallback` * `_.curry` * `_.debounce` * `_.defer` @@ -114,7 +114,6 @@ * `_.once` * `_.partial` * `_.partialRight` -* `_.property` * `_.throttle` * `_.wrap` @@ -137,7 +136,7 @@ * `_.forOwn` * `_.forOwnRight` * `_.functions` -* `_.has` +* `_.has` * `_.invert` * `_.isArguments` * `_.isArray` @@ -157,6 +156,7 @@ * `_.isString` * `_.isUndefined` * `_.keys` +* `_.mapValues` * `_.merge` * `_.methods -> functions` * `_.omit` @@ -172,14 +172,17 @@ ## `Utilities` * `_.now` +* `_.constant` +* `_.createCallback` * `_.escape` * `_.identity` * `_.mixin` * `_.noConflict` * `_.noop` * `_.parseInt` +* `_.property` * `_.random` -* `_.result` +* `_.result` * `_.runInContext` * `_.template` * `_.times` @@ -236,7 +239,7 @@ ### `_.compact(array)` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4389 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4435 "View in source") [Ⓣ][1] Creates an array with all falsey values removed. The values `false`, `null`, `0`, `""`, `undefined`, and `NaN` are all falsey. @@ -260,7 +263,7 @@ _.compact([0, 1, false, 2, '', 3]); ### `_.difference(array, [values])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4418 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4464 "View in source") [Ⓣ][1] Creates an array excluding all values of the provided arrays using strict equality for comparisons, i.e. `===`. @@ -285,7 +288,7 @@ _.difference([1, 2, 3, 4, 5], [5, 2, 10]); ### `_.findIndex(array, [callback=identity], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4463 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4509 "View in source") [Ⓣ][1] This method is like `_.find` except that it returns the index of the first element that passes the callback check, instead of the element itself. @@ -331,7 +334,7 @@ _.findIndex(characters, 'blocked'); ### `_.findLastIndex(array, [callback=identity], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4517 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4563 "View in source") [Ⓣ][1] This method is like `_.findIndex` except that it iterates over elements of a `collection` from right to left. @@ -377,7 +380,7 @@ _.findLastIndex(characters, 'blocked'); ### `_.first(array, [callback], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4579 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4625 "View in source") [Ⓣ][1] Gets the first element or first `n` elements of an array. If a callback is provided elements at the beginning of the array are returned as long as the callback returns truey. The callback is bound to `thisArg` and invoked with three arguments; *(value, index, array)*. @@ -432,7 +435,7 @@ _.pluck(_.first(characters, { 'employer': 'slate' }), 'name'); ### `_.flatten(array, [isShallow=false], [callback=identity], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4639 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4685 "View in source") [Ⓣ][1] Flattens a nested array *(the nesting can be to any depth)*. If `isShallow` is truey, the array will only be flattened a single level. If a callback is provided each element of the array is passed through the callback before flattening. The callback is bound to `thisArg` and invoked with three arguments; *(value, index, array)*. @@ -475,7 +478,7 @@ _.flatten(characters, 'pets'); ### `_.indexOf(array, value, [fromIndex=0])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4676 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4722 "View in source") [Ⓣ][1] Gets the index at which the first occurrence of `value` is found using strict equality for comparisons, i.e. `===`. If the array is already sorted providing `true` for `fromIndex` will run a faster binary search. @@ -507,7 +510,7 @@ _.indexOf([1, 1, 2, 2, 3, 3], 2, true); ### `_.initial(array, [callback=1], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4737 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4783 "View in source") [Ⓣ][1] Gets all but the last element or last `n` elements of an array. If a callback is provided elements at the end of the array are excluded from the result as long as the callback returns truey. The callback is bound to `thisArg` and invoked with three arguments; *(value, index, array)*. @@ -559,7 +562,7 @@ _.pluck(_.initial(characters, { 'employer': 'na' }), 'name'); ### `_.intersection([array])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4767 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4813 "View in source") [Ⓣ][1] Creates an array of unique values present in all provided arrays using strict equality for comparisons, i.e. `===`. @@ -567,11 +570,11 @@ Creates an array of unique values present in all provided arrays using strict eq 1. `[array]` *(...Array)*: The arrays to inspect. #### Returns -*(Array)*: Returns an array of composite values. +*(Array)*: Returns an array of shared values. #### Example ```js -_.intersection([1, 2, 3], [101, 2, 1, 10], [2, 1]); +_.intersection([1, 2, 3], [5, 2, 1, 4], [2, 1]); // => [1, 2] ``` @@ -583,7 +586,7 @@ _.intersection([1, 2, 3], [101, 2, 1, 10], [2, 1]); ### `_.last(array, [callback], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4862 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4913 "View in source") [Ⓣ][1] Gets the last element or last `n` elements of an array. If a callback is provided elements at the end of the array are returned as long as the callback returns truey. The callback is bound to `thisArg` and invoked with three arguments; *(value, index, array)*. @@ -635,7 +638,7 @@ _.last(characters, { 'employer': 'na' }); ### `_.lastIndexOf(array, value, [fromIndex=array.length-1])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4908 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4959 "View in source") [Ⓣ][1] Gets the index at which the last occurrence of `value` is found using strict equality for comparisons, i.e. `===`. If `fromIndex` is negative, it is used as the offset from the end of the collection. @@ -668,7 +671,7 @@ _.lastIndexOf([1, 2, 3, 1, 2, 3], 2, 3); ### `_.pull(array, [value])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4938 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4989 "View in source") [Ⓣ][1] Removes all provided values from the given array using strict equality for comparisons, i.e. `===`. @@ -695,7 +698,7 @@ console.log(array); ### `_.range([start=0], end, [step=1])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4989 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5040 "View in source") [Ⓣ][1] Creates an array of numbers *(positive and/or negative)* progressing from `start` up to but not including `end`. If `start` is less than `stop` a zero-length range is created unless a negative `step` is specified. @@ -736,7 +739,7 @@ _.range(0); ### `_.remove(array, [callback=identity], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5042 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5093 "View in source") [Ⓣ][1] Removes all elements from an array that the callback returns truey for and returns an array of removed elements. The callback is bound to `thisArg` and invoked with three arguments; *(value, index, array)*. @@ -772,7 +775,7 @@ console.log(evens); ### `_.rest(array, [callback=1], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5111 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5162 "View in source") [Ⓣ][1] The opposite of `_.initial` this method gets all but the first element or first `n` elements of an array. If a callback function is provided elements at the beginning of the array are excluded from the result as long as the callback returns truey. The callback is bound to `thisArg` and invoked with three arguments; *(value, index, array)*. @@ -827,7 +830,7 @@ _.rest(characters, { 'employer': 'slate' }); ### `_.sortedIndex(array, value, [callback=identity], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5175 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5226 "View in source") [Ⓣ][1] Uses a binary search to determine the smallest index at which a value should be inserted into a given sorted array in order to maintain the sort order of the array. If a callback is provided it will be executed for `value` and each element of `array` to compute their sort ranking. The callback is bound to `thisArg` and invoked with one argument; *(value)*. @@ -876,7 +879,7 @@ _.sortedIndex(['twenty', 'thirty', 'fifty'], 'fourty', function(word) { ### `_.union([array])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5206 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5257 "View in source") [Ⓣ][1] Creates an array of unique values, in order, of the provided arrays using strict equality for comparisons, i.e. `===`. @@ -884,12 +887,12 @@ Creates an array of unique values, in order, of the provided arrays using strict 1. `[array]` *(...Array)*: The arrays to inspect. #### Returns -*(Array)*: Returns an array of composite values. +*(Array)*: Returns an array of combined values. #### Example ```js -_.union([1, 2, 3], [101, 2, 1, 10], [2, 1]); -// => [1, 2, 3, 101, 10] +_.union([1, 2, 3], [5, 2, 1, 4], [2, 1]); +// => [1, 2, 3, 5, 4] ``` * * * @@ -900,7 +903,7 @@ _.union([1, 2, 3], [101, 2, 1, 10], [2, 1]); ### `_.uniq(array, [isSorted=false], [callback=identity], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5254 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5305 "View in source") [Ⓣ][1] Creates a duplicate-value-free version of an array using strict equality for comparisons, i.e. `===`. If the array is sorted, providing `true` for `isSorted` will use a faster algorithm. If a callback is provided each element of `array` is passed through the callback before uniqueness is computed. The callback is bound to `thisArg` and invoked with three arguments; *(value, index, array)*. @@ -947,7 +950,7 @@ _.uniq([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x'); ### `_.without(array, [value])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5282 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5333 "View in source") [Ⓣ][1] Creates an array excluding all provided values using strict equality for comparisons, i.e. `===`. @@ -969,10 +972,37 @@ _.without([1, 2, 1, 0, 3, 1, 4], 0, 1); + + +### `_.xor([array])` +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5354 "View in source") [Ⓣ][1] + +Creates an array that is the smymetric difference of the provided arrays. See http://en.wikipedia.org/wiki/Symmetric_difference. + +#### Arguments +1. `[array]` *(...Array)*: The arrays to inspect. + +#### Returns +*(Array)*: Returns an array of values. + +#### Example +```js +_.xor([1, 2, 3], [5, 2, 1, 4]); +// => [3, 5, 4] + +_.xor([1, 2, 5], [2, 3, 5], [3, 4, 5]); +// => [1, 4, 5] +``` + +* * * + + + + ### `_.zip([array])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5302 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5384 "View in source") [Ⓣ][1] Creates an array of grouped elements, the first of which contains the first elements of the given arrays, the second of which contains the second elements of the given arrays, and so on. @@ -999,7 +1029,7 @@ _.zip(['fred', 'barney'], [30, 40], [true, false]); ### `_.zipObject(keys, [values=[]])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5332 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5414 "View in source") [Ⓣ][1] Creates an object composed from arrays of `keys` and `values`. Provide either a single two dimensional array, i.e. `[[key1, value1], [key2, value2]]` or two arrays, one of `keys` and one of corresponding `values`. @@ -1089,7 +1119,7 @@ _.isArray(squares.value()); ### `_.chain(value)` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6629 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6732 "View in source") [Ⓣ][1] Creates a `lodash` object that wraps the given value with explicit method chaining enabled. @@ -1123,7 +1153,7 @@ var youngest = _.chain(characters) ### `_.tap(value, interceptor)` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6655 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6758 "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. @@ -1151,7 +1181,7 @@ _([1, 2, 3, 4]) ### `_.prototype.chain()` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6685 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6788 "View in source") [Ⓣ][1] Enables explicit method chaining on the wrapper object. @@ -1185,7 +1215,7 @@ _(characters).chain() ### `_.prototype.toString()` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6702 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6805 "View in source") [Ⓣ][1] Produces the `toString` result of the wrapped value. @@ -1206,7 +1236,7 @@ _([1, 2, 3]).toString(); ### `_.prototype.valueOf()` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6719 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6822 "View in source") [Ⓣ][1] Extracts the wrapped value. @@ -1237,7 +1267,7 @@ _([1, 2, 3]).valueOf(); ### `_.at(collection, [index])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L3230 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L3276 "View in source") [Ⓣ][1] Creates an array of elements from the specified indexes, or keys, of the `collection`. Indexes may be specified as individual arguments or as arrays of indexes. @@ -1265,7 +1295,7 @@ _.at(['fred', 'barney', 'pebbles'], 0, 2); ### `_.contains(collection, target, [fromIndex=0])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L3273 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L3319 "View in source") [Ⓣ][1] Checks if a given value is present in a collection using strict equality for comparisons, i.e. `===`. If `fromIndex` is negative, it is used as the offset from the end of the collection. @@ -1303,7 +1333,7 @@ _.contains('pebbles', 'eb'); ### `_.countBy(collection, [callback=identity], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L3328 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L3374 "View in source") [Ⓣ][1] Creates an object composed of keys generated from the results of running each element of `collection` through the callback. The corresponding value of each key is the number of times the key was returned by the callback. The callback is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. @@ -1339,7 +1369,7 @@ _.countBy(['one', 'two', 'three'], 'length'); ### `_.every(collection, [callback=identity], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L3373 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L3419 "View in source") [Ⓣ][1] Checks if the given callback returns truey value for **all** elements of a collection. The callback is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. @@ -1385,7 +1415,7 @@ _.every(characters, { 'age': 36 }); ### `_.filter(collection, [callback=identity], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L3434 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L3480 "View in source") [Ⓣ][1] Iterates over elements of a collection, returning an array of all elements the callback returns truey for. The callback is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. @@ -1431,7 +1461,7 @@ _.filter(characters, { 'age': 36 }); ### `_.find(collection, [callback=identity], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L3501 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L3547 "View in source") [Ⓣ][1] Iterates over elements of a collection, returning the first element that the callback returns truey for. The callback is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. @@ -1480,7 +1510,7 @@ _.find(characters, 'blocked'); ### `_.findLast(collection, [callback=identity], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L3546 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L3592 "View in source") [Ⓣ][1] This method is like `_.find` except that it iterates over elements of a `collection` from right to left. @@ -1508,7 +1538,7 @@ _.findLast([1, 2, 3, 4], function(num) { ### `_.forEach(collection, [callback=identity], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L3584 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L3630 "View in source") [Ⓣ][1] Iterates over elements of a collection, executing the callback for each element. The callback is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. Callbacks may exit iteration early by explicitly returning `false`. @@ -1542,7 +1572,7 @@ _.forEach({ 'one': 1, 'two': 2, 'three': 3 }, function(num) { console.log(num); ### `_.forEachRight(collection, [callback=identity], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L3617 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L3663 "View in source") [Ⓣ][1] This method is like `_.forEach` except that it iterates over elements of a `collection` from right to left. @@ -1571,7 +1601,7 @@ _([1, 2, 3]).forEachRight(function(num) { console.log(num); }).join(','); ### `_.groupBy(collection, [callback=identity], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L3678 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L3724 "View in source") [Ⓣ][1] Creates an object composed of keys generated from the results of running each element of a collection through the callback. The corresponding value of each key is an array of the elements responsible for generating the key. The callback is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. @@ -1608,7 +1638,7 @@ _.groupBy(['one', 'two', 'three'], 'length'); ### `_.indexBy(collection, [callback=identity], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L3721 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L3767 "View in source") [Ⓣ][1] Creates an object composed of keys generated from the results of running each element of the collection through the given callback. The corresponding value of each key is the last element responsible for generating the key. The callback is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. @@ -1649,7 +1679,7 @@ _.indexBy(characters, function(key) { this.fromCharCode(key.code); }, String); ### `_.invoke(collection, methodName, [arg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L3747 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L3793 "View in source") [Ⓣ][1] Invokes the method named by `methodName` on each element in the `collection` returning an array of the results of each invoked method. Additional arguments will be provided to each invoked method. If `methodName` is a function it will be invoked for, and `this` bound to, each element in the `collection`. @@ -1678,7 +1708,7 @@ _.invoke([123, 456], String.prototype.split, ''); ### `_.map(collection, [callback=identity], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L3799 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L3845 "View in source") [Ⓣ][1] Creates an array of values by running each element in the collection through the callback. The callback is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. @@ -1723,7 +1753,7 @@ _.map(characters, 'name'); ### `_.max(collection, [callback=identity], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L3857 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L3903 "View in source") [Ⓣ][1] Retrieves the maximum value of a collection. If the collection is empty or falsey `-Infinity` is returned. If a callback is provided it will be executed for each value in the collection to generate the criterion by which the value is ranked. The callback is bound to `thisArg` and invoked with three arguments; *(value, index, collection)*. @@ -1765,7 +1795,7 @@ _.max(characters, 'age'); ### `_.min(collection, [callback=identity], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L3932 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L3978 "View in source") [Ⓣ][1] Retrieves the minimum value of a collection. If the collection is empty or falsey `Infinity` is returned. If a callback is provided it will be executed for each value in the collection to generate the criterion by which the value is ranked. The callback is bound to `thisArg` and invoked with three arguments; *(value, index, collection)*. @@ -1807,7 +1837,7 @@ _.min(characters, 'age'); ### `_.pluck(collection, property)` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L3987 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4033 "View in source") [Ⓣ][1] Retrieves the value of a specified property from all elements in the collection. @@ -1837,7 +1867,7 @@ _.pluck(characters, 'name'); ### `_.reduce(collection, [callback=identity], [accumulator], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4019 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4065 "View in source") [Ⓣ][1] Reduces a collection to a value which is the accumulated result of running each element in the collection through the callback, where each successive callback execution consumes the return value of the previous execution. If `accumulator` is not provided the first element of the collection will be used as the initial `accumulator` value. The callback is bound to `thisArg` and invoked with four arguments; *(accumulator, value, index|key, collection)*. @@ -1875,7 +1905,7 @@ var mapped = _.reduce({ 'a': 1, 'b': 2, 'c': 3 }, function(result, num, key) { ### `_.reduceRight(collection, [callback=identity], [accumulator], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4062 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4108 "View in source") [Ⓣ][1] This method is like `_.reduce` except that it iterates over elements of a `collection` from right to left. @@ -1906,7 +1936,7 @@ var flat = _.reduceRight(list, function(a, b) { return a.concat(b); }, []); ### `_.reject(collection, [callback=identity], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4111 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4157 "View in source") [Ⓣ][1] The opposite of `_.filter` this method returns the elements of a collection that the callback does **not** return truey for. @@ -1949,7 +1979,7 @@ _.reject(characters, { 'age': 36 }); ### `_.sample(collection, [n])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4137 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4183 "View in source") [Ⓣ][1] Retrieves a random element or `n` random elements from a collection. @@ -1977,7 +2007,7 @@ _.sample([1, 2, 3, 4], 2); ### `_.shuffle(collection)` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4165 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4211 "View in source") [Ⓣ][1] Creates an array of shuffled values, using a version of the Fisher-Yates shuffle. See http://en.wikipedia.org/wiki/Fisher-Yates_shuffle. @@ -2001,7 +2031,7 @@ _.shuffle([1, 2, 3, 4, 5, 6]); ### `_.size(collection)` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4198 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4244 "View in source") [Ⓣ][1] Gets the size of the `collection` by returning `collection.length` for arrays and array-like objects or the number of own enumerable properties for objects. @@ -2031,7 +2061,7 @@ _.size('pebbles'); ### `_.some(collection, [callback=identity], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4245 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4291 "View in source") [Ⓣ][1] Checks if the callback returns a truey value for **any** element of a collection. The function returns as soon as it finds a passing value and does not iterate over the entire collection. The callback is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. @@ -2077,7 +2107,7 @@ _.some(characters, { 'age': 1 }); ### `_.sortBy(collection, [callback=identity], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4301 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4347 "View in source") [Ⓣ][1] Creates an array of elements, sorted in ascending order by the results of running each element in a collection through the callback. This method performs a stable sort, that is, it will preserve the original sort order of equal elements. The callback is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. @@ -2114,7 +2144,7 @@ _.sortBy(['banana', 'strawberry', 'apple'], 'length'); ### `_.toArray(collection)` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4337 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4383 "View in source") [Ⓣ][1] Converts the `collection` to an array. @@ -2138,7 +2168,7 @@ Converts the `collection` to an array. ### `_.where(collection, props)` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4371 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4417 "View in source") [Ⓣ][1] Performs a deep comparison of each element in a `collection` to the given `properties` object, returning an array of all elements that have equivalent property values. @@ -2178,7 +2208,7 @@ _.where(characters, { 'pets': ['dino'] }); ### `_.after(n, func)` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5377 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5459 "View in source") [Ⓣ][1] Creates a function that executes `func`, with the `this` binding and arguments of the created function, only after being called `n` times. @@ -2211,7 +2241,7 @@ _.forEach(saves, function(type) { ### `_.bind(func, [thisArg], [arg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5410 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5492 "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 provided to the bound function. @@ -2242,7 +2272,7 @@ func(); ### `_.bindAll(object, [methodName])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5440 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5522 "View in source") [Ⓣ][1] Binds methods of an object to the object itself, 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. @@ -2273,7 +2303,7 @@ jQuery('#docs').on('click', view.onClick); ### `_.bindKey(object, key, [arg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5486 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5568 "View in source") [Ⓣ][1] Creates a function that, when called, invokes the method at `object[key]` and prepends any additional `bindKey` arguments to those provided 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. @@ -2314,7 +2344,7 @@ func(); ### `_.compose([func])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5522 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5604 "View in source") [Ⓣ][1] Creates a function that is the composition of the provided 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. @@ -2349,49 +2379,10 @@ welcome('pebbles'); - - -### `_.createCallback([func=identity], [thisArg], [argCount])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5573 "View in source") [Ⓣ][1] - -Produces a callback bound to an optional `thisArg`. If `func` is a property name the created callback will return the property value for a given element. If `func` is an object the created callback will return `true` for elements that contain the equivalent object properties, otherwise it will return `false`. - -#### Arguments -1. `[func=identity]` *(*)*: The value to convert to a callback. -2. `[thisArg]` *(*)*: The `this` binding of the created callback. -3. `[argCount]` *(number)*: The number of arguments the callback accepts. - -#### Returns -*(Function)*: Returns a callback function. - -#### Example -```js -var characters = [ - { 'name': 'barney', 'age': 36 }, - { 'name': 'fred', 'age': 40 } -]; - -// wrap to create custom callback shorthands -_.createCallback = _.wrap(_.createCallback, function(func, callback, thisArg) { - var match = /^(.+?)__([gl]t)(.+)$/.exec(callback); - return !match ? func(callback, thisArg) : function(object) { - return match[2] == 'gt' ? object[match[1]] > match[3] : object[match[1]] < match[3]; - }; -}); - -_.filter(characters, 'age__gt38'); -// => [{ 'name': 'fred', 'age': 40 }] -``` - -* * * - - - - ### `_.curry(func, [arity=func.length])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5636 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5652 "View in source") [Ⓣ][1] Creates a function which accepts one or more arguments of `func` that when invoked either executes `func` returning its result, if all `func` arguments have been provided, or returns a function that accepts one or more of the remaining `func` arguments, and so on. The arity of `func` can be specified if `func.length` is not sufficient. @@ -2426,7 +2417,7 @@ curried(1, 2, 3); ### `_.debounce(func, wait, [options], [options.maxWait])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5680 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5696 "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. Provide an options object to indicate that `func` should be invoked on the leading and/or trailing edge of the `wait` timeout. Subsequent calls to the debounced function will return the result of the last `func` call. @@ -2470,7 +2461,7 @@ source.addEventListener('message', _.debounce(batchLog, 250, { ### `_.defer(func, [arg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5796 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5812 "View in source") [Ⓣ][1] Defers executing the `func` function until the current call stack has cleared. Additional arguments will be provided to `func` when it is invoked. @@ -2495,7 +2486,7 @@ _.defer(function(text) { console.log(text); }, 'deferred'); ### `_.delay(func, wait, [arg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5829 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5845 "View in source") [Ⓣ][1] Executes the `func` function after `wait` milliseconds. Additional arguments will be provided to `func` when it is invoked. @@ -2521,7 +2512,7 @@ _.delay(function(text) { console.log(text); }, 1000, 'later'); ### `_.memoize(func, [resolver])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5874 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5890 "View in source") [Ⓣ][1] Creates a function that memoizes the result of `func`. If `resolver` is provided it will be used to determine the cache key for storing the result based on the arguments provided to the memoized function. By default, the first argument provided to the memoized function is used as the cache key. The `func` is executed with the `this` binding of the memoized function. The result cache is exposed as the `cache` property on the memoized function. @@ -2564,7 +2555,7 @@ get('pebbles'); ### `_.once(func)` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5907 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5923 "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. @@ -2590,7 +2581,7 @@ initialize(); ### `_.partial(func, [arg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5945 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5961 "View in source") [Ⓣ][1] Creates a function that, when called, invokes `func` with any additional `partial` arguments prepended to those provided to the new function. This method is similar to `_.bind` except it does **not** alter the `this` binding. @@ -2617,7 +2608,7 @@ hi('fred'); ### `_.partialRight(func, [arg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5976 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L5992 "View in source") [Ⓣ][1] This method is like `_.partial` except that `partial` arguments are appended to those provided to the new function. @@ -2651,44 +2642,10 @@ options.imports - - -### `_.property(prop)` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6004 "View in source") [Ⓣ][1] - -Creates a "_.pluck" style function, which returns the `prop` value of a given object. - -#### Arguments -1. `prop` *(string)*: The name of the property to retrieve. - -#### Returns -*(*)*: Returns the new function. - -#### Example -```js -var characters = [ - { 'name': 'fred', 'age': 40 }, - { 'name': 'barney', 'age': 36 } -]; - -var getName = _.property('name'); - -_.map(characters, getName); -// => ['barney', 'fred'] - -_.sortBy(characters, getName); -// => [{ 'name': 'barney', 'age': 36 }, { 'name': 'fred', 'age': 40 }] -``` - -* * * - - - - ### `_.throttle(func, wait, [options])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6041 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6027 "View in source") [Ⓣ][1] Creates a function that, when executed, will only call the `func` function at most once per every `wait` milliseconds. Provide an options object to indicate that `func` should be invoked on the leading and/or trailing edge of the `wait` timeout. Subsequent calls to the throttled function will return the result of the last `func` call. @@ -2724,7 +2681,7 @@ jQuery('.interactive').on('click', _.throttle(renewToken, 300000, { ### `_.wrap(value, wrapper)` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6082 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6068 "View in source") [Ⓣ][1] Creates a function that provides `value` to the wrapper function as its first argument. Additional arguments provided to the function are appended to those provided to the wrapper function. The wrapper is executed with the `this` binding of the created function. @@ -3207,14 +3164,14 @@ _.functions(_); -### `_.has(object, prop)` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L2511 "View in source") [Ⓣ][1] +### `_.has(object, key)` +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L2511 "View in source") [Ⓣ][1] Checks if the specified property name exists as a direct property of `object`, instead of an inherited property. #### Arguments 1. `object` *(Object)*: The object to inspect. -2. `prop` *(string)*: The name of the property to check. +2. `key` *(string)*: The name of the property to check. #### Returns *(boolean)*: Returns `true` if key is a direct property, else `false`. @@ -3766,10 +3723,49 @@ _.keys({ 'one': 1, 'two': 2, 'three': 3 }); + + +### `_.mapValues(object, [callback=identity], [thisArg])` +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L2953 "View in source") [Ⓣ][1] + +Creates an object with the same keys as `object` and values generated by running each own enumerable property of `object` through the callback. The callback is bound to `thisArg` and invoked with three arguments; *(value, key, object)*. + +If a property name is provided for `callback` the created "_.pluck" style callback will return the property value of the given element. + +If an object is provided for `callback` the created "_.where" style callback will return `true` for elements that have the properties of the given object, else `false`. + +#### Arguments +1. `object` *(Object)*: The object to iterate over. +2. `[callback=identity]` *(Function|Object|string)*: The function called per iteration. If a property name or object is provided it will be used to create a "_.pluck" or "_.where" style callback, respectively. +3. `[thisArg]` *(*)*: The `this` binding of `callback`. + +#### Returns +*(Array)*: Returns a new object with values of the results of each `callback` execution. + +#### Example +```js +_.mapValues({ 'a': 1, 'b': 2, 'c': 3} , function(num) { return num * 3; }); +// => { 'a': 3, 'b': 6, 'c': 9 } + +var characters = { + 'fred': { 'name': 'fred', 'age': 40 }, + 'pebbles': { 'name': 'pebbles', 'age': 1 } +}; + +// using "_.pluck" callback shorthand +_.mapValues(characters, 'age'); +// => { 'fred': 40, 'pebbles': 1 } +``` + +* * * + + + + ### `_.merge(object, [source], [callback], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L2968 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L3014 "View in source") [Ⓣ][1] Recursively merges own enumerable properties of the source object(s), that don't resolve to `undefined` into the destination object. Subsequent sources will overwrite property assignments of previous sources. If a callback is provided it will be executed to produce the merged values of the destination and source properties. If the callback returns `undefined` merging will be handled by the method instead. The callback is bound to `thisArg` and invoked with two arguments; *(objectValue, sourceValue)*. @@ -3825,7 +3821,7 @@ _.merge(food, otherFood, function(a, b) { ### `_.omit(object, [callback], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L3025 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L3071 "View in source") [Ⓣ][1] Creates a shallow clone of `object` excluding the specified properties. Property names may be specified as individual arguments or as arrays of property names. If a callback is provided it will be executed for each property of `object` omitting the properties the callback returns truey for. The callback is bound to `thisArg` and invoked with three arguments; *(value, key, object)*. @@ -3856,7 +3852,7 @@ _.omit({ 'name': 'fred', 'age': 40 }, function(value) { ### `_.pairs(object)` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L3066 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L3112 "View in source") [Ⓣ][1] Creates a two dimensional array of an object's key-value pairs, i.e. `[[key1, value1], [key2, value2]]`. @@ -3880,7 +3876,7 @@ _.pairs({ 'barney': 36, 'fred': 40 }); ### `_.pick(object, [callback], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L3106 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L3152 "View in source") [Ⓣ][1] Creates a shallow clone of `object` composed of the specified properties. Property names may be specified as individual arguments or as arrays of property names. If a callback is provided it will be executed for each property of `object` picking the properties the callback returns truey for. The callback is bound to `thisArg` and invoked with three arguments; *(value, key, object)*. @@ -3911,9 +3907,9 @@ _.pick({ 'name': 'fred', '_userid': 'fred1' }, function(value, key) { ### `_.transform(object, [callback=identity], [accumulator], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L3161 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L3207 "View in source") [Ⓣ][1] -An alternative to `_.reduce` this method transforms `object` to a new `accumulator` object which is the result of running each of its elements through a callback, with each callback execution potentially mutating the `accumulator` object. The callback is bound to `thisArg` and invoked with four arguments; *(accumulator, value, key, object)*. Callbacks may exit iteration early by explicitly returning `false`. +An alternative to `_.reduce` this method transforms `object` to a new `accumulator` object which is the result of running each of its own enumerable properties through a callback, with each callback execution potentially mutating the `accumulator` object. The callback is bound to `thisArg` and invoked with four arguments; *(accumulator, value, key, object)*. Callbacks may exit iteration early by explicitly returning `false`. #### Arguments 1. `object` *(Array|Object)*: The object to iterate over. @@ -3948,7 +3944,7 @@ var mapped = _.transform({ 'a': 1, 'b': 2, 'c': 3 }, function(result, num, key) ### `_.values(object)` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L3195 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L3241 "View in source") [Ⓣ][1] Creates an array composed of the own enumerable property values of `object`. @@ -3979,7 +3975,7 @@ _.values({ 'one': 1, 'two': 2, 'three': 3 }); ### `_.now` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6222 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6295 "View in source") [Ⓣ][1] *(unknown)*: Gets the number of milliseconds that have elapsed since the Unix epoch *(1 January `1970 00`:00:00 UTC)*. @@ -3995,10 +3991,75 @@ _.defer(function() { console.log(_.now() - stamp); }); + + +### `_.constant(value)` +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6089 "View in source") [Ⓣ][1] + +Creates a function that returns `value`. + +#### Arguments +1. `value` *(*)*: The value to return from the new function. + +#### Returns +*(Function)*: Returns the new function. + +#### Example +```js +var object = { 'name': 'fred' }; +var getter = _.constant(object); +getter() === object; +// => true +``` + +* * * + + + + + + +### `_.createCallback([func=identity], [thisArg], [argCount])` +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6126 "View in source") [Ⓣ][1] + +Produces a callback bound to an optional `thisArg`. If `func` is a property name the created callback will return the property value for a given element. If `func` is an object the created callback will return `true` for elements that contain the equivalent object properties, otherwise it will return `false`. + +#### Arguments +1. `[func=identity]` *(*)*: The value to convert to a callback. +2. `[thisArg]` *(*)*: The `this` binding of the created callback. +3. `[argCount]` *(number)*: The number of arguments the callback accepts. + +#### Returns +*(Function)*: Returns a callback function. + +#### Example +```js +var characters = [ + { 'name': 'barney', 'age': 36 }, + { 'name': 'fred', 'age': 40 } +]; + +// wrap to create custom callback shorthands +_.createCallback = _.wrap(_.createCallback, function(func, callback, thisArg) { + var match = /^(.+?)__([gl]t)(.+)$/.exec(callback); + return !match ? func(callback, thisArg) : function(object) { + return match[2] == 'gt' ? object[match[1]] > match[3] : object[match[1]] < match[3]; + }; +}); + +_.filter(characters, 'age__gt38'); +// => [{ 'name': 'fred', 'age': 40 }] +``` + +* * * + + + + ### `_.escape(string)` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6102 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6175 "View in source") [Ⓣ][1] Converts the characters `&`, `<`, `>`, `"`, and `'` in `string` to their corresponding HTML entities. @@ -4022,7 +4083,7 @@ _.escape('Fred, Wilma, & Pebbles'); ### `_.identity(value)` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6120 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6193 "View in source") [Ⓣ][1] This method returns the first argument provided to it. @@ -4047,7 +4108,7 @@ _.identity(object) === object; ### `_.mixin(object, object)` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6147 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6220 "View in source") [Ⓣ][1] Adds function properties of a source object to the `lodash` function and chainable wrapper. @@ -4078,7 +4139,7 @@ _('fred').capitalize(); ### `_.noConflict()` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6188 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6261 "View in source") [Ⓣ][1] Reverts the '_' variable to its previous value and returns a reference to the `lodash` function. @@ -4098,7 +4159,7 @@ var lodash = _.noConflict(); ### `_.noop()` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6205 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6278 "View in source") [Ⓣ][1] A no-operation function. @@ -4117,7 +4178,7 @@ _.noop(object) === undefined; ### `_.parseInt(value, [radix])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6245 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6318 "View in source") [Ⓣ][1] Converts the given value into an integer of the specified radix. If `radix` is `undefined` or `0` a `radix` of `10` is used unless the `value` is a hexadecimal, in which case a `radix` of `16` is used. @@ -4141,10 +4202,44 @@ _.parseInt('08'); + + +### `_.property(key)` +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6347 "View in source") [Ⓣ][1] + +Creates a "_.pluck" style function, which returns the `key` value of a given object. + +#### Arguments +1. `key` *(string)*: The name of the property to retrieve. + +#### Returns +*(Function)*: Returns the new function. + +#### Example +```js +var characters = [ + { 'name': 'fred', 'age': 40 }, + { 'name': 'barney', 'age': 36 } +]; + +var getName = _.property('name'); + +_.map(characters, getName); +// => ['barney', 'fred'] + +_.sortBy(characters, getName); +// => [{ 'name': 'barney', 'age': 36 }, { 'name': 'fred', 'age': 40 }] +``` + +* * * + + + + ### `_.random([min=0], [max=1], [floating=false])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6277 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6380 "View in source") [Ⓣ][1] Produces a random number between `min` and `max` *(inclusive)*. If only one argument is provided a number between `0` and the given number will be returned. If `floating` is truey or either `min` or `max` are floats a floating-point number will be returned instead of an integer. @@ -4178,14 +4273,14 @@ _.random(1.2, 5.2); -### `_.result(object, prop)` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6335 "View in source") [Ⓣ][1] +### `_.result(object, key)` +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6438 "View in source") [Ⓣ][1] -Resolves the value of `prop` on `object`. If `prop` is a function it will be invoked with the `this` binding of `object` and its result returned, else the property value is returned. If `object` is falsey then `undefined` is returned. +Resolves the value of property `key` on `object`. If `key` is a function it will be invoked with the `this` binding of `object` and its result returned, else the property value is returned. If `object` is falsey then `undefined` is returned. #### Arguments 1. `object` *(Object)*: The object to inspect. -2. `prop` *(string)*: The name of the property to resolve. +2. `key` *(string)*: The name of the property to resolve. #### Returns *(*)*: Returns the resolved value. @@ -4232,7 +4327,7 @@ Create a new `lodash` function using the given context object. ### `_.template(text, data, [options], [options.escape], [options.evaluate], [options.imports], [options.interpolate], [sourceURL], [variable])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6428 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6531 "View in source") [Ⓣ][1] A micro-templating method that handles arbitrary delimiters, preserves whitespace, and correctly escapes quotes within interpolated code. @@ -4326,7 +4421,7 @@ fs.writeFileSync(path.join(cwd, 'jst.js'), '\ ### `_.times(n, callback, [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6551 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6654 "View in source") [Ⓣ][1] Executes the callback `n` times, returning an array of the results of each callback execution. The callback is bound to `thisArg` and invoked with one argument; *(index)*. @@ -4358,7 +4453,7 @@ _.times(3, function(n) { this.cast(n); }, mage); ### `_.unescape(string)` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6578 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6681 "View in source") [Ⓣ][1] The inverse of `_.escape` this method converts the HTML entities `&`, `<`, `>`, `"`, and `'` in `string` to their corresponding characters. @@ -4382,7 +4477,7 @@ _.unescape('Fred, Barney & Pebbles'); ### `_.uniqueId([prefix])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6598 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6701 "View in source") [Ⓣ][1] Generates a unique ID. If `prefix` is provided the ID will be appended to it. @@ -4435,7 +4530,7 @@ A reference to the `lodash` function. ### `_.VERSION` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6921 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L7027 "View in source") [Ⓣ][1] *(string)*: The semantic version number. diff --git a/lodash.js b/lodash.js index 7a64231da..103f5013b 100644 --- a/lodash.js +++ b/lodash.js @@ -2501,15 +2501,15 @@ * @memberOf _ * @category Objects * @param {Object} object The object to inspect. - * @param {string} prop The name of the property to check. + * @param {string} key The name of the property to check. * @returns {boolean} Returns `true` if key is a direct property, else `false`. * @example * * _.has({ 'a': 1, 'b': 2, 'c': 3 }, 'b'); * // => true */ - function has(object, prop) { - return object ? hasOwnProperty.call(object, prop) : false; + function has(object, key) { + return object ? hasOwnProperty.call(object, key) : false; } /** @@ -2914,6 +2914,52 @@ return typeof value == 'undefined'; } + /** + * Creates an object with the same keys as `object` and values generated by + * running each own enumerable property of `object` through the callback. + * The callback is bound to `thisArg` and invoked with three arguments; + * (value, key, object). + * + * If a property name is provided for `callback` the created "_.pluck" style + * callback will return the property value of the given element. + * + * If an object is provided for `callback` the created "_.where" style callback + * will return `true` for elements that have the properties of the given object, + * else `false`. + * + * @static + * @memberOf _ + * @category Objects + * @param {Object} object The object to iterate over. + * @param {Function|Object|string} [callback=identity] The function called + * per iteration. If a property name or object is provided it will be used + * to create a "_.pluck" or "_.where" style callback, respectively. + * @param {*} [thisArg] The `this` binding of `callback`. + * @returns {Array} Returns a new object with values of the results of each `callback` execution. + * @example + * + * _.mapValues({ 'a': 1, 'b': 2, 'c': 3} , function(num) { return num * 3; }); + * // => { 'a': 3, 'b': 6, 'c': 9 } + * + * var characters = { + * 'fred': { 'name': 'fred', 'age': 40 }, + * 'pebbles': { 'name': 'pebbles', 'age': 1 } + * }; + * + * // using "_.pluck" callback shorthand + * _.mapValues(characters, 'age'); + * // => { 'fred': 40, 'pebbles': 1 } + */ + function mapValues(object, callback, thisArg) { + var result = {}; + callback = lodash.createCallback(callback, thisArg, 3); + + forOwn(object, function(value, key, object) { + result[key] = callback(value, key, object); + }); + return result; + } + /** * Recursively merges own enumerable properties of the source object(s), that * don't resolve to `undefined` into the destination object. Subsequent sources @@ -3129,11 +3175,11 @@ /** * An alternative to `_.reduce` this method transforms `object` to a new - * `accumulator` object which is the result of running each of its elements - * through a callback, with each callback execution potentially mutating - * the `accumulator` object. The callback is bound to `thisArg` and invoked - * with four arguments; (accumulator, value, key, object). Callbacks may exit - * iteration early by explicitly returning `false`. + * `accumulator` object which is the result of running each of its own + * enumerable properties through a callback, with each callback execution + * potentially mutating the `accumulator` object. The callback is bound to + * `thisArg` and invoked with four arguments; (accumulator, value, key, object). + * Callbacks may exit iteration early by explicitly returning `false`. * * @static * @memberOf _ @@ -4758,29 +4804,34 @@ * @memberOf _ * @category Arrays * @param {...Array} [array] The arrays to inspect. - * @returns {Array} Returns an array of composite values. + * @returns {Array} Returns an array of shared values. * @example * - * _.intersection([1, 2, 3], [101, 2, 1, 10], [2, 1]); + * _.intersection([1, 2, 3], [5, 2, 1, 4], [2, 1]); * // => [1, 2] */ - function intersection(array) { - var args = arguments, - argsLength = args.length, + function intersection() { + var args = [], argsIndex = -1, + argsLength = arguments.length, caches = getArray(), - index = -1, indexOf = getIndexOf(), - length = array ? array.length : 0, - result = [], + trustIndexOf = indexOf === baseIndexOf, seen = getArray(); while (++argsIndex < argsLength) { - var value = args[argsIndex]; - caches[argsIndex] = indexOf === baseIndexOf && - (value ? value.length : 0) >= largeArraySize && - createCache(argsIndex ? args[argsIndex] : seen); + var value = arguments[argsIndex]; + if (isArray(value) || isArguments(value)) { + args.push(value); + caches.push(trustIndexOf && value.length >= largeArraySize && + createCache(argsIndex ? args[argsIndex] : seen)); + } } + var array = args[0], + index = -1, + length = array ? array.length : 0, + result = []; + outer: while (++index < length) { var cache = caches[0]; @@ -5197,13 +5248,13 @@ * @memberOf _ * @category Arrays * @param {...Array} [array] The arrays to inspect. - * @returns {Array} Returns an array of composite values. + * @returns {Array} Returns an array of combined values. * @example * - * _.union([1, 2, 3], [101, 2, 1, 10], [2, 1]); - * // => [1, 2, 3, 101, 10] + * _.union([1, 2, 3], [5, 2, 1, 4], [2, 1]); + * // => [1, 2, 3, 5, 4] */ - function union(array) { + function union() { return baseUniq(baseFlatten(arguments, true, true)); } @@ -5283,6 +5334,37 @@ return baseDifference(array, slice(arguments, 1)); } + /** + * Creates an array that is the smymetric difference of the provided arrays. + * See http://en.wikipedia.org/wiki/Symmetric_difference. + * + * @static + * @memberOf _ + * @category Arrays + * @param {...Array} [array] The arrays to inspect. + * @returns {Array} Returns an array of values. + * @example + * + * _.xor([1, 2, 3], [5, 2, 1, 4]); + * // => [3, 5, 4] + * + * _.xor([1, 2, 5], [2, 3, 5], [3, 4, 5]); + * // => [1, 4, 5] + */ + function xor() { + var index = 0, + length = arguments.length, + result = arguments[0] || []; + + while (++index < length) { + var array = arguments[index]; + if (isArray(array) || isArguments(array)) { + result = baseUniq(baseDifference(result, array).concat(baseDifference(array, result))); + } + } + return result; + } + /** * Creates an array of grouped elements, the first of which contains the first * elements of the given arrays, the second of which contains the second @@ -5989,6 +6071,27 @@ /*--------------------------------------------------------------------------*/ + /** + * Creates a function that returns `value`. + * + * @static + * @memberOf _ + * @category Utilities + * @param {*} value The value to return from the new function. + * @returns {Function} Returns the new function. + * @example + * + * var object = { 'name': 'fred' }; + * var getter = _.constant(object); + * getter() === object; + * // => true + */ + function constant(value) { + return function() { + return value; + }; + } + /** * Produces a callback bound to an optional `thisArg`. If `func` is a property * name the created callback will return the property value for a given element. @@ -6218,14 +6321,14 @@ }; /** - * Creates a "_.pluck" style function, which returns the `prop` value of a + * Creates a "_.pluck" style function, which returns the `key` value of a * given object. * * @static * @memberOf _ * @category Utilities - * @param {string} prop The name of the property to retrieve. - * @returns {*} Returns the new function. + * @param {string} key The name of the property to retrieve. + * @returns {Function} Returns the new function. * @example * * var characters = [ @@ -6241,9 +6344,9 @@ * _.sortBy(characters, getName); * // => [{ 'name': 'barney', 'age': 36 }, { 'name': 'fred', 'age': 40 }] */ - function property(prop) { + function property(key) { return function(object) { - return object[prop]; + return object[key]; }; } @@ -6306,7 +6409,7 @@ } /** - * Resolves the value of `prop` on `object`. If `prop` is a function + * Resolves the value of property `key` on `object`. If `key` is a function * it will be invoked with the `this` binding of `object` and its result returned, * else the property value is returned. If `object` is falsey then `undefined` * is returned. @@ -6315,7 +6418,7 @@ * @memberOf _ * @category Utilities * @param {Object} object The object to inspect. - * @param {string} prop The name of the property to resolve. + * @param {string} key The name of the property to resolve. * @returns {*} Returns the resolved value. * @example * @@ -6332,10 +6435,10 @@ * _.result(object, 'stuff'); * // => 'nonsense' */ - function result(object, prop) { + function result(object, key) { if (object) { - var value = object[prop]; - return isFunction(value) ? object[prop]() : value; + var value = object[key]; + return isFunction(value) ? object[key]() : value; } } @@ -6732,6 +6835,7 @@ lodash.chain = chain; lodash.compact = compact; lodash.compose = compose; + lodash.constant = constant; lodash.countBy = countBy; lodash.create = create; lodash.createCallback = createCallback; @@ -6758,6 +6862,7 @@ lodash.invoke = invoke; lodash.keys = keys; lodash.map = map; + lodash.mapValues = mapValues; lodash.max = max; lodash.memoize = memoize; lodash.merge = merge; @@ -6788,6 +6893,7 @@ lodash.where = where; lodash.without = without; lodash.wrap = wrap; + lodash.xor = xor; lodash.zip = zip; lodash.zipObject = zipObject; diff --git a/test/test.js b/test/test.js index 56715e8b1..4be6f09b8 100644 --- a/test/test.js +++ b/test/test.js @@ -1019,6 +1019,25 @@ /*--------------------------------------------------------------------------*/ + QUnit.module('lodash.constant'); + + (function() { + test('should create a function that always returns `value`', 1, function() { + var object = { 'a': 1 }, + values = falsey.concat(1, 'a'), + constant = _.constant(object), + expected = _.map(values, function() { return object; }); + + var actual = _.map(values, function(value, index) { + return index ? constant(value) : constant(); + }); + + deepEqual(actual, expected); + }); + }()); + + /*--------------------------------------------------------------------------*/ + QUnit.module('lodash.contains'); (function() { @@ -1736,7 +1755,7 @@ deepEqual(_.difference(array1, array2), []); }); - test('should not accept individual secondary values', 1, function() { + test('should ignore individual secondary values', 1, function() { var array = [1, null, 3]; deepEqual(_.difference(array, null, 3), array); }); @@ -2391,7 +2410,7 @@ test('`_.' + methodName + '` should return a wrapped value when chaining', 1, function() { if (!isNpm) { - var actual = _(array)[methodName](Boolean); + var actual = _(array)[methodName](noop); ok(actual instanceof _); } else { @@ -2425,7 +2444,7 @@ test('`_.' + methodName + '` should return the existing wrapper when chaining', 1, function() { if (!isNpm) { var wrapper = _(array); - equal(wrapper[methodName](Boolean), wrapper); + equal(wrapper[methodName](noop), wrapper); } else { skipTest(); @@ -3066,18 +3085,18 @@ (function() { test('should return the intersection of the given arrays', 1, function() { - var actual = _.intersection([1, 3, 2], [101, 2, 1, 10], [2, 1]); + var actual = _.intersection([1, 3, 2], [5, 2, 1, 4], [2, 1]); deepEqual(actual, [1, 2]); }); test('should return an array of unique values', 1, function() { - var actual = _.intersection([1, 1, 3, 2, 2], [101, 2, 2, 1, 101], [2, 1, 1]); + var actual = _.intersection([1, 1, 3, 2, 2], [5, 2, 2, 1, 4], [2, 1, 1]); deepEqual(actual, [1, 2]); }); test('should return a wrapped value when chaining', 2, function() { if (!isNpm) { - var actual = _([1, 3, 2]).intersection([101, 2, 1, 10]); + var actual = _([1, 3, 2]).intersection([5, 2, 1, 4]); ok(actual instanceof _); deepEqual(actual.value(), [1, 2]); } @@ -3085,6 +3104,10 @@ skipTest(2); } }); + + test('should ignore individual secondary values', 1, function() { + deepEqual(_.intersection([1, null, 3], 3, null), []); + }); }()); /*--------------------------------------------------------------------------*/ @@ -4628,22 +4651,22 @@ test('should support the `thisArg` argument', 2, function() { function callback(num, index) { - return this[index]; + return this[index] + num; } var actual = _.map([1], callback, [2]); - equal(actual, 2); + deepEqual(actual, [3]); actual = _.map({ 'a': 1 }, callback, { 'a': 2 }); - equal(actual, 2); + deepEqual(actual, [3]); }); test('should iterate over own properties of objects', 1, function() { function Foo() { this.a = 1; } Foo.prototype.b = 2; - var keys = _.map(new Foo, function(value, key) { return key; }); - deepEqual(keys, ['a']); + var actual = _.map(new Foo, function(value, key) { return key; }); + deepEqual(actual, ['a']); }); test('should work on an object with no `callback`', 1, function() { @@ -4663,7 +4686,7 @@ test('should return a wrapped value when chaining', 1, function() { if (!isNpm) { - ok(_(array).map(Boolean) instanceof _); + ok(_(array).map(noop) instanceof _); } else { skipTest(); @@ -4702,6 +4725,70 @@ /*--------------------------------------------------------------------------*/ + QUnit.module('lodash.mapValues'); + + (function() { + var object = { 'a': 1, 'b': 2, 'c': 3 }; + + test('should pass the correct `callback` arguments', 1, function() { + var args; + + _.mapValues(object, function() { + args || (args = slice.call(arguments)); + }); + + deepEqual(args, [1, 'a', object]); + }); + + test('should support the `thisArg` argument', 2, function() { + function callback(num, key) { + return this[key] + num; + } + + var actual = _.mapValues({ 'a': 1 }, callback, { 'a': 2 }); + deepEqual(actual, { 'a': 3 }); + + actual = _.mapValues([1], callback, [2]); + deepEqual(actual, { '0': 3 }); + }); + + test('should iterate over own properties of objects', 1, function() { + function Foo() { this.a = 1; } + Foo.prototype.b = 2; + + var actual = _.mapValues(new Foo, function(value, key) { return key; }); + deepEqual(actual, { 'a': 'a' }); + }); + + test('should work on an object with no `callback`', 1, function() { + var actual = _.mapValues({ 'a': 1, 'b': 2, 'c': 3 }); + deepEqual(actual, object); + }); + + test('should return a wrapped value when chaining', 1, function() { + if (!isNpm) { + ok(_(object).mapValues(noop) instanceof _); + } + else { + skipTest(); + } + }); + + test('should accept a falsey `object` argument', 1, function() { + var expected = _.map(falsey, function() { return {}; }); + + var actual = _.map(falsey, function(value, index) { + try { + return index ? _.mapValues(value) : _.mapValues(); + } catch(e) { } + }); + + deepEqual(actual, expected); + }); + }()); + + /*--------------------------------------------------------------------------*/ + QUnit.module('lodash.max'); (function() { @@ -5488,7 +5575,7 @@ QUnit.module('lodash.property'); (function() { - test('should great a function that plucks a property value of a given object', 3, function() { + test('should create a function that plucks a property value of a given object', 3, function() { var object = { 'a': 1, 'b': 2 }, actual = _.property('a'); @@ -7364,13 +7451,13 @@ (function() { test('should return the union of the given arrays', 1, function() { - var actual = _.union([1, 2, 3], [101, 2, 1, 10], [2, 1]); - deepEqual(actual, [1, 2, 3, 101, 10]); + var actual = _.union([1, 2, 3], [5, 2, 1, 4], [2, 1]); + deepEqual(actual, [1, 2, 3, 5, 4]); }); test('should not flatten nested arrays', 1, function() { - var actual = _.union([1, 2, 3], [1, [4]], [2, [5]]); - deepEqual(actual, [1, 2, 3, [4], [5]]); + var actual = _.union([1, 2, 3], [1, [5]], [2, [4]]); + deepEqual(actual, [1, 2, 3, [5], [4]]); }); test('should produce correct results when provided a falsey `array` argument', 1, function() { @@ -7380,8 +7467,9 @@ deepEqual(actual, expected); }); - test('should not accept individual secondary values', 1, function() { - deepEqual(_.union([1], 1, 2, 3), [1]); + test('should ignore individual secondary values', 1, function() { + var array = [1]; + deepEqual(_.union(array, 1, 2, 3), array); }); }()); @@ -7633,6 +7721,38 @@ /*--------------------------------------------------------------------------*/ + QUnit.module('lodash.xor'); + + (function() { + test('should return the symmetric difference of the given arrays', 1, function() { + var actual = _.xor([1, 2, 5], [2, 3, 5], [3, 4, 5]); + deepEqual(actual, [1, 4, 5]); + }); + + test('should return an array of unique values', 1, function() { + var actual = _.xor([1, 1, 2, 5], [2, 2, 3, 5], [3, 4, 5, 5]); + deepEqual(actual, [1, 4, 5]); + }); + + test('should return a wrapped value when chaining', 2, function() { + if (!isNpm) { + var actual = _([1, 2, 3]).xor([5, 2, 1, 4]); + ok(actual instanceof _); + deepEqual(actual.value(), [3, 5, 4]); + } + else { + skipTest(2); + } + }); + + test('should ignore individual secondary values', 1, function() { + var array = [1, null, 3]; + deepEqual(_.xor(array, 3, null), array); + }); + }()); + + /*--------------------------------------------------------------------------*/ + QUnit.module('lodash.zip'); (function() { @@ -8067,6 +8187,7 @@ 'values', 'where', 'without', + 'xor', 'zip' ]; @@ -8089,7 +8210,7 @@ var acceptFalsey = _.difference(allMethods, rejectFalsey); - test('should accept falsey arguments', 151, function() { + test('should accept falsey arguments', 155, function() { var isExported = '_' in root, oldDash = root._;