From 95be8b2cf3f884d58a71db8b367b5486fa9f274c Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sat, 28 Dec 2013 19:56:52 -0600 Subject: [PATCH] Optimize `_.sortBy` by adding `baseCompareAscending` and `compareMultipleAscending`. --- dist/lodash.compat.js | 75 +++++++++++++++-------- dist/lodash.compat.min.js | 112 +++++++++++++++++----------------- dist/lodash.js | 75 +++++++++++++++-------- dist/lodash.min.js | 102 +++++++++++++++---------------- dist/lodash.underscore.js | 56 ++++++++--------- dist/lodash.underscore.min.js | 4 +- lodash.js | 75 +++++++++++++++-------- 7 files changed, 283 insertions(+), 216 deletions(-) diff --git a/dist/lodash.compat.js b/dist/lodash.compat.js index 4e8c43029..4a465de2f 100644 --- a/dist/lodash.compat.js +++ b/dist/lodash.compat.js @@ -198,6 +198,27 @@ /*--------------------------------------------------------------------------*/ + /** + * The base implementation of `compareAscending` used to compare values and + * sort them in ascending order without guaranteeing a stable sort. + * + * @private + * @param {*} a The value to compare to `b`. + * @param {*} b The value to compare to `a`. + * @returns {number} Returns the sort order indicator for `a`. + */ + function baseCompareAscending(a, b) { + if (a !== b) { + if (a > b || typeof a == 'undefined') { + return 1; + } + if (a < b || typeof b == 'undefined') { + return -1; + } + } + return 0; + } + /** * The base implementation of `_.indexOf` without support for binary searches * or `fromIndex` constraints. @@ -287,36 +308,42 @@ } /** - * Used by `sortBy` to compare transformed `collection` elements, stable sorting - * them in ascending order. + * Used by `sortBy` to compare transformed elements of a collection and stable + * sort them in ascending order. * * @private * @param {Object} a The object to compare to `b`. * @param {Object} b The object to compare to `a`. - * @returns {number} Returns the sort order indicator of `1` or `-1`. + * @returns {number} Returns the sort order indicator for `a`. */ function compareAscending(a, b) { + return baseCompareAscending(a.criteria, b.criteria) || a.index - b.index; + } + + /** + * Used by `sortBy` to compare multiple properties of each element in a + * collection and stable sort them in ascending order. + * + * @private + * @param {Object} a The object to compare to `b`. + * @param {Object} b The object to compare to `a`. + * @returns {number} Returns the sort order indicator for `a`. + */ + function compareMultipleAscending(a, b) { var ac = a.criteria, bc = b.criteria, index = -1, length = ac.length; while (++index < length) { - var value = ac[index], - other = bc[index]; - - if (value !== other) { - if (value > other || typeof value == 'undefined') { - return 1; - } - if (value < other || typeof other == 'undefined') { - return -1; - } + var result = baseCompareAscending(ac[index], bc[index]); + if (result) { + return result; } } // Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications - // that causes it, under certain circumstances, to return the same value for - // `a` and `b`. See https://github.com/jashkenas/underscore/pull/1247 + // that causes it, under certain circumstances, to provided the same value + // for `a` and `b`. See https://github.com/jashkenas/underscore/pull/1247 // // This also ensures a stable sort in V8 and other engines. // See http://code.google.com/p/v8/issues/detail?id=90 @@ -4257,6 +4284,7 @@ result[index] = result[rand]; result[rand] = value; }); + return result; } @@ -4399,32 +4427,27 @@ */ function sortBy(collection, callback, thisArg) { var index = -1, - isArr = isArray(callback), + multi = callback && isArray(callback), length = collection ? collection.length : 0, result = Array(typeof length == 'number' ? length : 0); - if (!isArr) { + if (!multi) { callback = lodash.createCallback(callback, thisArg, 3); } forEach(collection, function(value, key, collection) { var object = result[++index] = getObject(); - if (isArr) { - object.criteria = map(callback, function(key) { return value[key]; }); - } else { - (object.criteria = getArray())[0] = callback(value, key, collection); - } object.index = index; object.value = value; + object.criteria = multi + ? map(callback, function(key) { return value[key]; }) + : callback(value, key, collection); }); length = result.length; - result.sort(compareAscending); + result.sort(multi ? compareMultipleAscending : compareAscending); while (length--) { var object = result[length]; result[length] = object.value; - if (!isArr) { - releaseArray(object.criteria); - } releaseObject(object); } return result; diff --git a/dist/lodash.compat.min.js b/dist/lodash.compat.min.js index 23bde1d48..e3c34ea38 100644 --- a/dist/lodash.compat.min.js +++ b/dist/lodash.compat.min.js @@ -3,59 +3,59 @@ * Lo-Dash 2.4.1 (Custom Build) lodash.com/license | Underscore.js 1.5.2 underscorejs.org/LICENSE * Build: `lodash -o ./dist/lodash.compat.js` */ -;(function(){function n(n,t,r){r=(r||0)-1;for(var e=n?n.length:0;++ri||typeof a=="undefined")return 1;if(ar?0:r);++e=b&&a===n,l=[];if(f){var c=o(e);c?(a=t,e=c):f=false}for(;++ua(e,c)&&l.push(c); -return f&&p(e),l}function ft(n,t,r){var e=-1,u=n,o=n?n.length:0;if(t=t&&typeof r=="undefined"?t:ut(t,r,3),typeof o=="number")for(Jr.unindexedChars&&Rt(u)&&(u=u.split(""));++e=b&&f===n,h=u||g?i():s;for(g&&(h=o(h),f=t);++af(h,y))&&((u||g)&&h.push(y),s.push(v))}return g?(c(h.g),p(h)):u&&c(h),s}function ht(n){return function(t,r,e){var u={};if(r=v.createCallback(r,e,3),Xr(t)){e=-1;for(var o=t.length;++eu;u++)e+="l='"+n.d[u]+"';if((!(k&&n[l])&&h.call(p,l))",n.f||(e+="||(!n[l]&&p[l]!==q[l])"),e+="){"+n.c+"}";e+="}"}return t("a,f,g,h,j,q,r,o,v,w,y",r+(e+"return s;")+"}")(ut,K,dr,Ar,jt,br,nt,Hr,H,_r,xr) -}function mt(n){return Y[n]}function dt(){var t=(t=v.indexOf)===Gt?n:t;return t}function bt(n){return typeof n=="function"&&Cr.test(Sr.call(n))}function _t(n){var t,r;return!n||xr.call(n)!=U||(t=n.constructor,It(t)&&!(t instanceof t))||!Jr.argsClass&&jt(n)||!Jr.nodeClass&&l(n)?false:Jr.ownLast?(ne(n,function(n,t,e){return r=Ar.call(e,t),false}),false!==r):(ne(n,function(n,t){r=t}),typeof r=="undefined"||Ar.call(n,r))}function wt(n){return Z[n]}function jt(n){return n&&typeof n=="object"&&typeof n.length=="number"&&xr.call(n)==B||false -}function xt(n,t,r){var e=arguments,u=0,o=typeof r=="number"?2:e.length;if(3=e)return false;if(typeof n=="string"||!Xr(n)&&Rt(n))return qr?qr.call(n,t,r):-1r?Kr(0,e+r):r)||0,-1o&&(o=i)}}else t=null==t&&Rt(n)?e:v.createCallback(t,r,3),ft(n,function(n,r,e){r=t(n,r,e),r>u&&(u=r,o=n)});return o}function zt(n,t,r,e){var u=3>arguments.length;if(t=v.createCallback(t,e,4),Xr(n)){var o=-1,a=n.length;for(u&&a&&(r=n[++o]);++oarguments.length;return t=v.createCallback(t,e,4),Bt(n,function(n,e,o){r=u?(u=false,n):t(r,n,e,o)}),r}function Mt(n){var t=-1,r=n?n.length:0,e=ir(typeof r=="number"?r:0);return Ft(n,function(n){var r=st(0,++t);e[t]=e[r],e[r]=n}),e}function Vt(n,t,r){var e;if(t=v.createCallback(t,r,3),Xr(n)){r=-1;for(var u=n.length;++re?Kr(0,u+e):e||0}else if(e)return e=Jt(t,r),t[e]===r?e:-1;return n(t,r,e)}function Ht(n,t,r){if(typeof t!="number"&&null!=t){var e=0,u=-1,o=n?n.length:0;for(t=v.createCallback(t,r,3);++u>>1,r(n[e])r?0:r);++t=h;m?(u&&(u=Or(u)),c=a,o=n.apply(i,e)):u||(u=Tr(y,h))}return m&&f?f=Or(f):f||t===p||(f=Tr(v,t)),r&&(m=true,o=n.apply(i,e)),!m||f||u||(e=i=null),o}}function tr(n){return n}function rr(n){n||(n={});var t=Zr(n),r=t[0],e=n[r];return 1!=t.length||e!==e||At(e)?function(r){for(var e=t.length,u=false;e--&&(u=ct(r[t[e]],n[t[e]],null,true)););return u}:function(n){return n=n[r],e===n&&(0!==e||1/e==1/n)}}function er(n,t,r){var e=true,u=t&&Et(t);t&&(r||u.length)||(null==r&&(r=t),o=y,t=n,n=v,u=Et(t)),false===r?e=false:At(r)&&"chain"in r&&(e=r.chain); -var o=n,a=It(o);Ft(u,function(r){var u=n[r]=t[r];a&&(o.prototype[r]=function(){var t=this.__chain__,r=this.__wrapped__,a=[r];if(Nr.apply(a,arguments),a=u.apply(n,a),e||t){if(r===a&&At(a))return this;a=new o(a),a.__chain__=t}return a})})}function ur(){}function or(n){return function(t){return t[n]}}function ar(){return this.__wrapped__}r=r?at.defaults(rt.Object(),r,at.pick(rt,q)):rt;var ir=r.Array,fr=r.Boolean,lr=r.Date,cr=r.Function,pr=r.Math,sr=r.Number,gr=r.Object,hr=r.RegExp,vr=r.String,yr=r.TypeError,mr=[],dr=r.Error.prototype,br=gr.prototype,_r=vr.prototype,wr=(wr=r.window)&&wr.document,jr=r._,xr=br.toString,Cr=hr("^"+vr(xr).replace(/[.*+?^${}()|[\]\\]/g,"\\$&").replace(/toString|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),kr=pr.ceil,Or=r.clearTimeout,Er=pr.floor,Sr=cr.prototype.toString,Ir=bt(Ir=gr.getPrototypeOf)&&Ir,Ar=br.hasOwnProperty,Nr=mr.push,Rr=br.propertyIsEnumerable,Tr=r.setTimeout,Pr=mr.splice,Dr=mr.unshift,$r=function(){try{var n={},t=bt(t=gr.defineProperty)&&t,r=t(n,n,n)&&t -}catch(e){}return r}(),qr=bt(qr=_r.contains)&&qr,Fr=bt(Fr=gr.create)&&Fr,Br=bt(Br=ir.isArray)&&Br,Lr=r.isFinite,Wr=r.isNaN,zr=bt(zr=gr.keys)&&zr,Kr=pr.max,Mr=pr.min,Vr=r.parseInt,Ur=pr.random,Gr={};Gr[L]=ir,Gr[W]=fr,Gr[z]=lr,Gr[M]=cr,Gr[U]=gr,Gr[V]=sr,Gr[G]=hr,Gr[H]=vr;var Hr={};Hr[L]=Hr[z]=Hr[V]={constructor:true,toLocaleString:true,toString:true,valueOf:true},Hr[W]=Hr[H]={constructor:true,toString:true,valueOf:true},Hr[K]=Hr[M]=Hr[G]={constructor:true,toString:true},Hr[U]={constructor:true},function(){for(var n=F.length;n--;){var t,r=F[n]; -for(t in Hr)Ar.call(Hr,t)&&!Ar.call(Hr[t],r)&&(Hr[t][r]=false)}}(),y.prototype=v.prototype;var Jr=v.support={};!function(){var n=function(){this.x=1},t={0:1,length:1},e=[];n.prototype={valueOf:1,y:1};for(var u in new n)e.push(u);for(u in arguments);Jr.argsClass=xr.call(arguments)==B,Jr.argsObject=arguments.constructor==gr&&!(arguments instanceof ir),Jr.enumErrorProps=Rr.call(dr,"message")||Rr.call(dr,"name"),Jr.enumPrototypes=Rr.call(n,"prototype"),Jr.funcDecomp=!bt(r.WinRTError)&&D.test(g),Jr.funcNames=typeof cr.name=="string",Jr.nonEnumArgs=0!=u,Jr.nonEnumShadows=!/valueOf/.test(e),Jr.ownLast="x"!=e[0],Jr.spliceObjects=(mr.splice.call(t,0,1),!t[0]),Jr.unindexedChars="xx"!="x"[0]+gr("x")[0]; -try{Jr.dom=11===wr.createDocumentFragment().nodeType}catch(o){Jr.dom=false}try{Jr.nodeClass=!(xr.call(undefined)==U&&!({toString:0}+""))}catch(a){Jr.nodeClass=true}}(1),v.templateSettings={escape:S,evaluate:I,interpolate:A,variable:"",imports:{_:v}},Fr||(et=function(){function n(){}return function(t){if(At(t)){n.prototype=t;var e=new n;n.prototype=null}return e||r.Object()}}());var Qr=$r?function(n,t){X.value=t,$r(n,"__bindData__",X)}:ur;Jr.argsClass||(jt=function(n){return n&&typeof n=="object"&&typeof n.length=="number"&&Ar.call(n,"callee")&&!Rr.call(n,"callee")||false -});var Xr=Br||function(n){return n&&typeof n=="object"&&typeof n.length=="number"&&xr.call(n)==L||false},Yr=yt({a:"p",b:"[]",e:"",c:"s.push(l)",f:true}),Zr=zr?function(n){return At(n)?Jr.enumPrototypes&&typeof n=="function"||Jr.nonEnumArgs&&n.length&&jt(n)?Yr(n):zr(n):[]}:Yr,ne=yt({a:"p,b,x",b:"p",e:"b=b&&typeof x=='undefined'?b:a(b,x,3)",c:"if(b(p[l],l,p)===false){return s}",f:false});Jr.dom||(St=function(n){return n&&typeof n=="object"&&1===n.nodeType&&!te(n)||false}),It(/x/)&&(It=function(n){return typeof n=="function"&&xr.call(n)==M -});var te=Ir?function(n){if(!n||xr.call(n)!=U||!Jr.argsClass&&jt(n))return false;var t=n.valueOf,r=bt(t)&&(r=Ir(t))&&Ir(r);return r?n==r||Ir(n)==r:_t(n)}:_t,re=ht(function(n,t,r){Ar.call(n,r)?n[r]++:n[r]=1}),ee=ht(function(n,t,r){(Ar.call(n,r)?n[r]:n[r]=[]).push(t)}),ue=ht(function(n,t,r){n[r]=t}),oe=Lt,ae=bt(ae=lr.now)&&ae||function(){return(new lr).getTime()},ie=8==Vr(w+"08")?Vr:function(n,t){return Vr(Rt(n)?n.replace(T,""):n,t||0)};return v.after=function(n,t){if(!It(t))throw new yr;return function(){return 1>--n?t.apply(this,arguments):void 0 -}},v.assign=xt,v.at=function(n){var t=arguments,r=-1,e=lt(t,true,false,1),t=t[2]&&t[2][t[1]]===n?1:e.length,u=ir(t);for(Jr.unindexedChars&&Rt(n)&&(n=n.split(""));++r=b&&o(e?r[e]:s)))}var l=r[0],h=-1,v=l?l.length:0,y=[];n:for(;++h(m?t(m,g):f(s,g))){for(e=u,(m||s).push(g);--e;)if(m=a[e],0>(m?t(m,g):f(r[e],g)))continue n;y.push(g)}}for(;u--;)(m=a[u])&&p(m);return c(a),c(s),y},v.invert=function(n,t){for(var r=-1,e=Zr(n),u=e.length,o={};++rr?Kr(0,e+r):Mr(r,e-1))+1);e--;)if(n[e]===t)return e;return-1},v.mixin=er,v.noConflict=function(){return r._=jr,this},v.noop=ur,v.now=ae,v.parseInt=ie,v.random=function(n,t,r){var e=null==n,u=null==t;return null==r&&(u&&typeof n=="boolean"?(r=n,n=1):typeof t=="boolean"&&(r=t,u=true)),e&&u&&(t=1,u=false),n=+n||0,u?(t=n,n=0):t=+t||0,r||n%1||t%1?(r=Ur(),Mr(n+r*(t-n+parseFloat("1e-"+((r+"").length-1))),t)):st(n,t) -},v.reduce=zt,v.reduceRight=Kt,v.result=function(n,t){if(n){var r=n[t];return It(r)?n[t]():r}},v.runInContext=g,v.size=function(n){var t=n?n.length:0;return typeof t=="number"?t:Zr(n).length},v.some=Vt,v.sortedIndex=Jt,v.template=function(n,t,r){var e=v.templateSettings;n=vr(n||""),r=Ct({},r,e);var u,o=Ct({},r.imports,e.imports),e=Zr(o),o=Tt(o),i=0,f=r.interpolate||P,l="__p+='",f=hr((r.escape||P).source+"|"+f.source+"|"+(f===A?k:P).source+"|"+(r.evaluate||P).source+"|$","g");n.replace(f,function(t,r,e,o,f,c){return e||(e=o),l+=n.slice(i,c).replace($,a),r&&(l+="'+__e("+r+")+'"),f&&(u=true,l+="';"+f+";\n__p+='"),e&&(l+="'+((__t=("+e+"))==null?'':__t)+'"),i=c+t.length,t -}),l+="';",f=r=r.variable,f||(r="obj",l="with("+r+"){"+l+"}"),l=(u?l.replace(j,""):l).replace(x,"$1").replace(C,"$1;"),l="function("+r+"){"+(f?"":r+"||("+r+"={});")+"var __t,__p='',__e=_.escape"+(u?",__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}":";")+l+"return __p}";try{var c=cr(e,"return "+l).apply(h,o)}catch(p){throw p.source=l,p}return t?c(t):(c.source=l,c)},v.unescape=function(n){return null==n?"":(n=vr(n),0>n.indexOf(";")?n:n.replace(N,wt))},v.uniqueId=function(n){var t=++m; -return vr(null==n?"":n)+t},v.all=Dt,v.any=Vt,v.detect=qt,v.findWhere=qt,v.foldl=zt,v.foldr=Kt,v.include=Pt,v.inject=zt,er(function(){var n={};return kt(v,function(t,r){v.prototype[r]||(n[r]=t)}),n}(),false),v.first=Ut,v.last=function(n,t,r){var e=0,u=n?n.length:0;if(typeof t!="number"&&null!=t){var o=u;for(t=v.createCallback(t,r,3);o--&&t(n[o],o,n);)e++}else if(e=t,null==e||r)return n?n[u-1]:h;return s(n,Kr(0,u-e))},v.sample=function(n,t,r){return n&&typeof n.length!="number"?n=Tt(n):Jr.unindexedChars&&Rt(n)&&(n=n.split("")),null==t||r?n?n[st(0,n.length-1)]:h:(n=Mt(n),n.length=Mr(Kr(0,t),n.length),n) -},v.take=Ut,v.head=Ut,kt(v,function(n,t){var r="sample"!==t;v.prototype[t]||(v.prototype[t]=function(t,e){var u=this.__chain__,o=n(this.__wrapped__,t,e);return u||null!=t&&(!e||r&&typeof t=="function")?new y(o,u):o})}),v.VERSION="2.4.1",v.prototype.chain=function(){return this.__chain__=true,this},v.prototype.toString=function(){return vr(this.__wrapped__)},v.prototype.value=ar,v.prototype.valueOf=ar,ft(["join","pop","shift"],function(n){var t=mr[n];v.prototype[n]=function(){var n=this.__chain__,r=t.apply(this.__wrapped__,arguments); -return n?new y(r,n):r}}),ft(["push","reverse","sort","unshift"],function(n){var t=mr[n];v.prototype[n]=function(){return t.apply(this.__wrapped__,arguments),this}}),ft(["concat","slice","splice"],function(n){var t=mr[n];v.prototype[n]=function(){return new y(t.apply(this.__wrapped__,arguments),this.__chain__)}}),Jr.spliceObjects||ft(["pop","shift","splice"],function(n){var t=mr[n],r="splice"==n;v.prototype[n]=function(){var n=this.__chain__,e=this.__wrapped__,u=t.apply(e,arguments);return 0===e.length&&delete e[0],n||r?new y(u,n):u -}}),v}var h,v=[],y=[],m=0,d=+new Date+"",b=75,_=40,w=" \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",j=/\b__p\+='';/g,x=/\b(__p\+=)''\+/g,C=/(__e\(.*?\)|\b__t\))\+'';/g,k=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,O=/\w*$/,E=/^\s*function[ \n\r\t]+\w/,S=/<%-([\s\S]+?)%>/g,I=/<%([\s\S]+?)%>/g,A=/<%=([\s\S]+?)%>/g,N=/&(?:amp|lt|gt|quot|#39);/g,R=/[&<>"']/g,T=RegExp("^["+w+"]*0+(?=.$)"),P=/($^)/,D=/\bthis\b/,$=/['\n\r\t\u2028\u2029\\]/g,q="Array Boolean Date Error Function Math Number Object RegExp String _ clearTimeout document isFinite isNaN parseInt setTimeout TypeError window WinRTError".split(" "),F="constructor hasOwnProperty isPrototypeOf propertyIsEnumerable toLocaleString toString valueOf".split(" "),B="[object Arguments]",L="[object Array]",W="[object Boolean]",z="[object Date]",K="[object Error]",M="[object Function]",V="[object Number]",U="[object Object]",G="[object RegExp]",H="[object String]",J={}; -J[M]=false,J[B]=J[L]=J[W]=J[z]=J[V]=J[U]=J[G]=J[H]=true;var Q={leading:false,maxWait:0,trailing:false},X={configurable:false,enumerable:false,value:null,writable:false},Y={"&":"&","<":"<",">":">",'"':""","'":"'"},Z={"&":"&","<":"<",">":">",""":'"',"'":"'"},nt={"boolean":false,"function":true,object:true,number:false,string:false,undefined:false},tt={"\\":"\\","'":"'","\n":"n","\r":"r","\t":"t","\u2028":"u2028","\u2029":"u2029"},rt=nt[typeof window]&&window||this,et=nt[typeof exports]&&exports&&!exports.nodeType&&exports,ut=nt[typeof global]&&global; -!ut||ut.global!==ut&&ut.window!==ut||(rt=ut);var ot=(ut=nt[typeof module]&&module&&!module.nodeType&&module)&&ut.exports===et&&et,at=g();typeof define=="function"&&typeof define.amd=="object"&&define.amd?(rt._=at, define(function(){return at})):et&&ut?ot?(ut.exports=at)._=at:et._=at:rt._=at}).call(this); \ No newline at end of file +;(function(){function n(n,t){if(n!==t){if(n>t||typeof n=="undefined")return 1;if(nr?0:r);++e=w&&o===t,l=[]; +if(f){var c=i(e);c?(o=r,e=c):f=false}for(;++uo(e,c)&&l.push(c);return f&&g(e),l}function lt(n,t,r){var e=-1,u=n,o=n?n.length:0;if(t=t&&typeof r=="undefined"?t:ot(t,r,3),typeof o=="number")for(Qr.unindexedChars&&Tt(u)&&(u=u.split(""));++e=w&&a===t,h=u||p?l():c;for(p&&(h=i(h),a=r);++oa(h,y))&&((u||p)&&h.push(y),c.push(v))}return p?(s(h.g),g(h)):u&&s(h),c}function vt(n){return function(t,r,u){var o={};if(r=e.createCallback(r,u,3),Yr(t)){u=-1;for(var a=t.length;++uu;u++)e+="l='"+n.d[u]+"';if((!(k&&n[l])&&h.call(p,l))",n.f||(e+="||(!n[l]&&p[l]!==q[l])"),e+="){"+n.c+"}";e+="}"}return t("a,f,g,h,j,q,r,o,v,w,y",r+(e+"return s;")+"}")(ot,V,br,Nr,xt,_r,rt,Jr,Q,wr,Cr) +}function dt(n){return nt[n]}function bt(){var n=(n=e.indexOf)===Ht?t:n;return n}function _t(n){return typeof n=="function"&&kr.test(Ir.call(n))}function wt(n){var t,r;return!n||Cr.call(n)!=H||(t=n.constructor,At(t)&&!(t instanceof t))||!Qr.argsClass&&xt(n)||!Qr.nodeClass&&p(n)?false:Qr.ownLast?(te(n,function(n,t,e){return r=Nr.call(e,t),false}),false!==r):(te(n,function(n,t){r=t}),typeof r=="undefined"||Nr.call(n,r))}function jt(n){return tt[n]}function xt(n){return n&&typeof n=="object"&&typeof n.length=="number"&&Cr.call(n)==W||false +}function Ct(n,t,r){var e=arguments,u=0,o=typeof r=="number"?2:e.length;if(3=e)return false;if(typeof n=="string"||!Yr(n)&&Tt(n))return Fr?Fr.call(n,t,r):-1r?Mr(0,e+r):r)||0,-1a&&(a=f)}}else t=null==t&&Tt(n)?u:e.createCallback(t,r,3),lt(n,function(n,r,e){r=t(n,r,e),r>o&&(o=r,a=n)});return a}function Kt(n,t,r,u){var o=3>arguments.length;if(t=e.createCallback(t,u,4),Yr(n)){var a=-1,i=n.length;for(o&&i&&(r=n[++a]);++aarguments.length;return t=e.createCallback(t,u,4),Lt(n,function(n,e,u){r=o?(o=false,n):t(r,n,e,u)}),r}function Vt(n){var t=-1,r=n?n.length:0,e=fr(typeof r=="number"?r:0);return Bt(n,function(n){var r=gt(0,++t);e[t]=e[r],e[r]=n}),e}function Ut(n,t,r){var u;if(t=e.createCallback(t,r,3),Yr(n)){r=-1;for(var o=n.length;++re?Mr(0,u+e):e||0}else if(e)return e=Qt(n,r),n[e]===r?e:-1;return t(n,r,e)}function Jt(n,t,r){if(typeof t!="number"&&null!=t){var u=0,o=-1,a=n?n.length:0;for(t=e.createCallback(t,r,3);++o>>1,r(n[u])r?0:r);++t=y;m?(u&&(u=Er(u)),c=a,o=n.apply(i,e)):u||(u=Pr(v,y))}return m&&f?f=Er(f):f||t===p||(f=Pr(h,t)),r&&(m=true,o=n.apply(i,e)),!m||f||u||(e=i=null),o}}function rr(n){return n}function er(n){n||(n={});var t=ne(n),r=t[0],e=n[r];return 1!=t.length||e!==e||Nt(e)?function(r){for(var e=t.length,u=false;e--&&(u=pt(r[t[e]],n[t[e]],null,true)););return u}:function(n){return n=n[r],e===n&&(0!==e||1/e==1/n)}}function ur(n,t,r){var u=true,o=t&&St(t);t&&(r||o.length)||(null==r&&(r=t),a=m,t=n,n=e,o=St(t)),false===r?u=false:Nt(r)&&"chain"in r&&(u=r.chain); +var a=n,i=At(a);Bt(o,function(r){var e=n[r]=t[r];i&&(a.prototype[r]=function(){var t=this.__chain__,r=this.__wrapped__,o=[r];if(Rr.apply(o,arguments),o=e.apply(n,o),u||t){if(r===o&&Nt(o))return this;o=new a(o),o.__chain__=t}return o})})}function or(){}function ar(n){return function(t){return t[n]}}function ir(){return this.__wrapped__}n=n?ft.defaults(ut.Object(),n,ft.pick(ut,B)):ut;var fr=n.Array,lr=n.Boolean,cr=n.Date,pr=n.Function,sr=n.Math,gr=n.Number,hr=n.Object,vr=n.RegExp,yr=n.String,mr=n.TypeError,dr=[],br=n.Error.prototype,_r=hr.prototype,wr=yr.prototype,jr=(jr=n.window)&&jr.document,xr=n._,Cr=_r.toString,kr=vr("^"+yr(Cr).replace(/[.*+?^${}()|[\]\\]/g,"\\$&").replace(/toString|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),Or=sr.ceil,Er=n.clearTimeout,Sr=sr.floor,Ir=pr.prototype.toString,Ar=_t(Ar=hr.getPrototypeOf)&&Ar,Nr=_r.hasOwnProperty,Rr=dr.push,Tr=_r.propertyIsEnumerable,Pr=n.setTimeout,Dr=dr.splice,$r=dr.unshift,qr=function(){try{var n={},t=_t(t=hr.defineProperty)&&t,r=t(n,n,n)&&t +}catch(e){}return r}(),Fr=_t(Fr=wr.contains)&&Fr,Br=_t(Br=hr.create)&&Br,Lr=_t(Lr=fr.isArray)&&Lr,Wr=n.isFinite,zr=n.isNaN,Kr=_t(Kr=hr.keys)&&Kr,Mr=sr.max,Vr=sr.min,Ur=n.parseInt,Gr=sr.random,Hr={};Hr[z]=fr,Hr[K]=lr,Hr[M]=cr,Hr[U]=pr,Hr[H]=hr,Hr[G]=gr,Hr[J]=vr,Hr[Q]=yr;var Jr={};Jr[z]=Jr[M]=Jr[G]={constructor:true,toLocaleString:true,toString:true,valueOf:true},Jr[K]=Jr[Q]={constructor:true,toString:true,valueOf:true},Jr[V]=Jr[U]=Jr[J]={constructor:true,toString:true},Jr[H]={constructor:true},function(){for(var n=L.length;n--;){var t,r=L[n]; +for(t in Jr)Nr.call(Jr,t)&&!Nr.call(Jr[t],r)&&(Jr[t][r]=false)}}(),m.prototype=e.prototype;var Qr=e.support={};!function(){var t=function(){this.x=1},r={0:1,length:1},e=[];t.prototype={valueOf:1,y:1};for(var u in new t)e.push(u);for(u in arguments);Qr.argsClass=Cr.call(arguments)==W,Qr.argsObject=arguments.constructor==hr&&!(arguments instanceof fr),Qr.enumErrorProps=Tr.call(br,"message")||Tr.call(br,"name"),Qr.enumPrototypes=Tr.call(t,"prototype"),Qr.funcDecomp=!_t(n.WinRTError)&&q.test(v),Qr.funcNames=typeof pr.name=="string",Qr.nonEnumArgs=0!=u,Qr.nonEnumShadows=!/valueOf/.test(e),Qr.ownLast="x"!=e[0],Qr.spliceObjects=(dr.splice.call(r,0,1),!r[0]),Qr.unindexedChars="xx"!="x"[0]+hr("x")[0]; +try{Qr.dom=11===jr.createDocumentFragment().nodeType}catch(o){Qr.dom=false}try{Qr.nodeClass=!(Cr.call(undefined)==H&&!({toString:0}+""))}catch(a){Qr.nodeClass=true}}(1),e.templateSettings={escape:A,evaluate:N,interpolate:R,variable:"",imports:{_:e}},Br||(et=function(){function t(){}return function(r){if(Nt(r)){t.prototype=r;var e=new t;t.prototype=null}return e||n.Object()}}());var Xr=qr?function(n,t){Z.value=t,qr(n,"__bindData__",Z)}:or;Qr.argsClass||(xt=function(n){return n&&typeof n=="object"&&typeof n.length=="number"&&Nr.call(n,"callee")&&!Tr.call(n,"callee")||false +});var Yr=Lr||function(n){return n&&typeof n=="object"&&typeof n.length=="number"&&Cr.call(n)==z||false},Zr=mt({a:"p",b:"[]",e:"",c:"s.push(l)",f:true}),ne=Kr?function(n){return Nt(n)?Qr.enumPrototypes&&typeof n=="function"||Qr.nonEnumArgs&&n.length&&xt(n)?Zr(n):Kr(n):[]}:Zr,te=mt({a:"p,b,x",b:"p",e:"b=b&&typeof x=='undefined'?b:a(b,x,3)",c:"if(b(p[l],l,p)===false){return s}",f:false});Qr.dom||(It=function(n){return n&&typeof n=="object"&&1===n.nodeType&&!re(n)||false}),At(/x/)&&(At=function(n){return typeof n=="function"&&Cr.call(n)==U +});var re=Ar?function(n){if(!n||Cr.call(n)!=H||!Qr.argsClass&&xt(n))return false;var t=n.valueOf,r=_t(t)&&(r=Ar(t))&&Ar(r);return r?n==r||Ar(n)==r:wt(n)}:wt,ee=vt(function(n,t,r){Nr.call(n,r)?n[r]++:n[r]=1}),ue=vt(function(n,t,r){(Nr.call(n,r)?n[r]:n[r]=[]).push(t)}),oe=vt(function(n,t,r){n[r]=t}),ae=Wt,ie=_t(ie=cr.now)&&ie||function(){return(new cr).getTime()},fe=8==Ur(x+"08")?Ur:function(n,t){return Ur(Tt(n)?n.replace(D,""):n,t||0)};return e.after=function(n,t){if(!At(t))throw new mr;return function(){return 1>--n?t.apply(this,arguments):void 0 +}},e.assign=Ct,e.at=function(n){var t=arguments,r=-1,e=ct(t,true,false,1),t=t[2]&&t[2][t[1]]===n?1:e.length,u=fr(t);for(Qr.unindexedChars&&Tt(n)&&(n=n.split(""));++r=w&&i(e?n[e]:c)))}var f=n[0],h=-1,v=f?f.length:0,y=[];n:for(;++h(m?r(m,p):a(c,p))){for(e=u,(m||c).push(p);--e;)if(m=o[e],0>(m?r(m,p):a(n[e],p)))continue n;y.push(p)}}for(;u--;)(m=o[u])&&g(m);return s(o),s(c),y},e.invert=function(n,t){for(var r=-1,e=ne(n),u=e.length,o={};++rr?Mr(0,e+r):Vr(r,e-1))+1);e--;)if(n[e]===t)return e;return-1},e.mixin=ur,e.noConflict=function(){return n._=xr,this},e.noop=or,e.now=ie,e.parseInt=fe,e.random=function(n,t,r){var e=null==n,u=null==t;return null==r&&(u&&typeof n=="boolean"?(r=n,n=1):typeof t=="boolean"&&(r=t,u=true)),e&&u&&(t=1,u=false),n=+n||0,u?(t=n,n=0):t=+t||0,r||n%1||t%1?(r=Gr(),Vr(n+r*(t-n+parseFloat("1e-"+((r+"").length-1))),t)):gt(n,t) +},e.reduce=Kt,e.reduceRight=Mt,e.result=function(n,t){if(n){var r=n[t];return At(r)?n[t]():r}},e.runInContext=v,e.size=function(n){var t=n?n.length:0;return typeof t=="number"?t:ne(n).length},e.some=Ut,e.sortedIndex=Qt,e.template=function(n,t,r){var u=e.templateSettings;n=yr(n||""),r=kt({},r,u);var o,a=kt({},r.imports,u.imports),u=ne(a),a=Pt(a),i=0,l=r.interpolate||$,c="__p+='",l=vr((r.escape||$).source+"|"+l.source+"|"+(l===R?E:$).source+"|"+(r.evaluate||$).source+"|$","g");n.replace(l,function(t,r,e,u,a,l){return e||(e=u),c+=n.slice(i,l).replace(F,f),r&&(c+="'+__e("+r+")+'"),a&&(o=true,c+="';"+a+";\n__p+='"),e&&(c+="'+((__t=("+e+"))==null?'':__t)+'"),i=l+t.length,t +}),c+="';",l=r=r.variable,l||(r="obj",c="with("+r+"){"+c+"}"),c=(o?c.replace(C,""):c).replace(k,"$1").replace(O,"$1;"),c="function("+r+"){"+(l?"":r+"||("+r+"={});")+"var __t,__p='',__e=_.escape"+(o?",__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}":";")+c+"return __p}";try{var p=pr(u,"return "+c).apply(y,a)}catch(s){throw s.source=c,s}return t?p(t):(p.source=c,p)},e.unescape=function(n){return null==n?"":(n=yr(n),0>n.indexOf(";")?n:n.replace(T,jt))},e.uniqueId=function(n){var t=++b; +return yr(null==n?"":n)+t},e.all=$t,e.any=Ut,e.detect=Ft,e.findWhere=Ft,e.foldl=Kt,e.foldr=Mt,e.include=Dt,e.inject=Kt,ur(function(){var n={};return Ot(e,function(t,r){e.prototype[r]||(n[r]=t)}),n}(),false),e.first=Gt,e.last=function(n,t,r){var u=0,o=n?n.length:0;if(typeof t!="number"&&null!=t){var a=o;for(t=e.createCallback(t,r,3);a--&&t(n[a],a,n);)u++}else if(u=t,null==u||r)return n?n[o-1]:y;return h(n,Mr(0,o-u))},e.sample=function(n,t,r){return n&&typeof n.length!="number"?n=Pt(n):Qr.unindexedChars&&Tt(n)&&(n=n.split("")),null==t||r?n?n[gt(0,n.length-1)]:y:(n=Vt(n),n.length=Vr(Mr(0,t),n.length),n) +},e.take=Gt,e.head=Gt,Ot(e,function(n,t){var r="sample"!==t;e.prototype[t]||(e.prototype[t]=function(t,e){var u=this.__chain__,o=n(this.__wrapped__,t,e);return u||null!=t&&(!e||r&&typeof t=="function")?new m(o,u):o})}),e.VERSION="2.4.1",e.prototype.chain=function(){return this.__chain__=true,this},e.prototype.toString=function(){return yr(this.__wrapped__)},e.prototype.value=ir,e.prototype.valueOf=ir,lt(["join","pop","shift"],function(n){var t=dr[n];e.prototype[n]=function(){var n=this.__chain__,r=t.apply(this.__wrapped__,arguments); +return n?new m(r,n):r}}),lt(["push","reverse","sort","unshift"],function(n){var t=dr[n];e.prototype[n]=function(){return t.apply(this.__wrapped__,arguments),this}}),lt(["concat","slice","splice"],function(n){var t=dr[n];e.prototype[n]=function(){return new m(t.apply(this.__wrapped__,arguments),this.__chain__)}}),Qr.spliceObjects||lt(["pop","shift","splice"],function(n){var t=dr[n],r="splice"==n;e.prototype[n]=function(){var n=this.__chain__,e=this.__wrapped__,u=t.apply(e,arguments);return 0===e.length&&delete e[0],n||r?new m(u,n):u +}}),e}var y,m=[],d=[],b=0,_=+new Date+"",w=75,j=40,x=" \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",C=/\b__p\+='';/g,k=/\b(__p\+=)''\+/g,O=/(__e\(.*?\)|\b__t\))\+'';/g,E=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,S=/\w*$/,I=/^\s*function[ \n\r\t]+\w/,A=/<%-([\s\S]+?)%>/g,N=/<%([\s\S]+?)%>/g,R=/<%=([\s\S]+?)%>/g,T=/&(?:amp|lt|gt|quot|#39);/g,P=/[&<>"']/g,D=RegExp("^["+x+"]*0+(?=.$)"),$=/($^)/,q=/\bthis\b/,F=/['\n\r\t\u2028\u2029\\]/g,B="Array Boolean Date Error Function Math Number Object RegExp String _ clearTimeout document isFinite isNaN parseInt setTimeout TypeError window WinRTError".split(" "),L="constructor hasOwnProperty isPrototypeOf propertyIsEnumerable toLocaleString toString valueOf".split(" "),W="[object Arguments]",z="[object Array]",K="[object Boolean]",M="[object Date]",V="[object Error]",U="[object Function]",G="[object Number]",H="[object Object]",J="[object RegExp]",Q="[object String]",X={}; +X[U]=false,X[W]=X[z]=X[K]=X[M]=X[G]=X[H]=X[J]=X[Q]=true;var Y={leading:false,maxWait:0,trailing:false},Z={configurable:false,enumerable:false,value:null,writable:false},nt={"&":"&","<":"<",">":">",'"':""","'":"'"},tt={"&":"&","<":"<",">":">",""":'"',"'":"'"},rt={"boolean":false,"function":true,object:true,number:false,string:false,undefined:false},et={"\\":"\\","'":"'","\n":"n","\r":"r","\t":"t","\u2028":"u2028","\u2029":"u2029"},ut=rt[typeof window]&&window||this,ot=rt[typeof exports]&&exports&&!exports.nodeType&&exports,at=rt[typeof global]&&global; +!at||at.global!==at&&at.window!==at||(ut=at);var it=(at=rt[typeof module]&&module&&!module.nodeType&&module)&&at.exports===ot&&ot,ft=v();typeof define=="function"&&typeof define.amd=="object"&&define.amd?(ut._=ft, define(function(){return ft})):ot&&at?it?(at.exports=ft)._=ft:ot._=ft:ut._=ft}).call(this); \ No newline at end of file diff --git a/dist/lodash.js b/dist/lodash.js index 4dbaaab86..b74a8b355 100644 --- a/dist/lodash.js +++ b/dist/lodash.js @@ -188,6 +188,27 @@ /*--------------------------------------------------------------------------*/ + /** + * The base implementation of `compareAscending` used to compare values and + * sort them in ascending order without guaranteeing a stable sort. + * + * @private + * @param {*} a The value to compare to `b`. + * @param {*} b The value to compare to `a`. + * @returns {number} Returns the sort order indicator for `a`. + */ + function baseCompareAscending(a, b) { + if (a !== b) { + if (a > b || typeof a == 'undefined') { + return 1; + } + if (a < b || typeof b == 'undefined') { + return -1; + } + } + return 0; + } + /** * The base implementation of `_.indexOf` without support for binary searches * or `fromIndex` constraints. @@ -277,36 +298,42 @@ } /** - * Used by `sortBy` to compare transformed `collection` elements, stable sorting - * them in ascending order. + * Used by `sortBy` to compare transformed elements of a collection and stable + * sort them in ascending order. * * @private * @param {Object} a The object to compare to `b`. * @param {Object} b The object to compare to `a`. - * @returns {number} Returns the sort order indicator of `1` or `-1`. + * @returns {number} Returns the sort order indicator for `a`. */ function compareAscending(a, b) { + return baseCompareAscending(a.criteria, b.criteria) || a.index - b.index; + } + + /** + * Used by `sortBy` to compare multiple properties of each element in a + * collection and stable sort them in ascending order. + * + * @private + * @param {Object} a The object to compare to `b`. + * @param {Object} b The object to compare to `a`. + * @returns {number} Returns the sort order indicator for `a`. + */ + function compareMultipleAscending(a, b) { var ac = a.criteria, bc = b.criteria, index = -1, length = ac.length; while (++index < length) { - var value = ac[index], - other = bc[index]; - - if (value !== other) { - if (value > other || typeof value == 'undefined') { - return 1; - } - if (value < other || typeof other == 'undefined') { - return -1; - } + var result = baseCompareAscending(ac[index], bc[index]); + if (result) { + return result; } } // Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications - // that causes it, under certain circumstances, to return the same value for - // `a` and `b`. See https://github.com/jashkenas/underscore/pull/1247 + // that causes it, under certain circumstances, to provided the same value + // for `a` and `b`. See https://github.com/jashkenas/underscore/pull/1247 // // This also ensures a stable sort in V8 and other engines. // See http://code.google.com/p/v8/issues/detail?id=90 @@ -3940,6 +3967,7 @@ result[index] = result[rand]; result[rand] = value; }); + return result; } @@ -4082,32 +4110,27 @@ */ function sortBy(collection, callback, thisArg) { var index = -1, - isArr = isArray(callback), + multi = callback && isArray(callback), length = collection ? collection.length : 0, result = Array(typeof length == 'number' ? length : 0); - if (!isArr) { + if (!multi) { callback = lodash.createCallback(callback, thisArg, 3); } forEach(collection, function(value, key, collection) { var object = result[++index] = getObject(); - if (isArr) { - object.criteria = map(callback, function(key) { return value[key]; }); - } else { - (object.criteria = getArray())[0] = callback(value, key, collection); - } object.index = index; object.value = value; + object.criteria = multi + ? map(callback, function(key) { return value[key]; }) + : callback(value, key, collection); }); length = result.length; - result.sort(compareAscending); + result.sort(multi ? compareMultipleAscending : compareAscending); while (length--) { var object = result[length]; result[length] = object.value; - if (!isArr) { - releaseArray(object.criteria); - } releaseObject(object); } return result; diff --git a/dist/lodash.min.js b/dist/lodash.min.js index 83a9d81ff..4b30bf322 100644 --- a/dist/lodash.min.js +++ b/dist/lodash.min.js @@ -3,54 +3,54 @@ * Lo-Dash 2.4.1 (Custom Build) lodash.com/license | Underscore.js 1.5.2 underscorejs.org/LICENSE * Build: `lodash modern -o ./dist/lodash.js` */ -;(function(){function n(n,t,e){e=(e||0)-1;for(var r=n?n.length:0;++ea||typeof i=="undefined")return 1;if(ie?0:e);++r=b&&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=b&&f===n,v=u||h?a():s;for(h&&(v=o(v),f=t);++if(v,y))&&((u||h)&&v.push(y),s.push(g)) -}return h?(l(v.g),c(v)):u&&l(v),s}function st(n){return function(t,e,r){var u={};e=d.createCallback(e,r,3),r=-1;var o=t?t.length:0;if(typeof o=="number")for(;++r=r)return false;if(typeof n=="string"||!Ue(n)&&It(n))return Te?Te.call(n,t,e):-1e?qe(0,r+e):e)||0,-1o&&(o=a)}}else t=null==t&&It(n)?r:d.createCallback(t,e,3),$t(n,function(n,e,r){e=t(n,e,r),e>u&&(u=e,o=n)});return o}function Wt(n,t,e,r){var u=3>arguments.length;t=d.createCallback(t,r,4);var o=-1,i=n?n.length:0;if(typeof i=="number")for(u&&i&&(e=n[++o]);++oarguments.length;return t=d.createCallback(t,r,4),Ft(n,function(n,r,o){e=u?(u=false,n):t(e,n,r,o) -}),e}function Pt(n){var t=-1,e=n?n.length:0,r=ue(typeof e=="number"?e:0);return $t(n,function(n){var e=ct(0,++t);r[t]=r[e],r[e]=n}),r}function Kt(n,t,e){var r;t=d.createCallback(t,e,3),e=-1;var u=n?n.length:0;if(typeof u=="number")for(;++er?qe(0,u+r):r||0}else if(r)return r=Ut(t,e),t[r]===e?r:-1;return n(t,e,r)}function Vt(n,t,e){if(typeof t!="number"&&null!=t){var r=0,u=-1,o=n?n.length:0;for(t=d.createCallback(t,e,3);++u>>1,e(n[r])e?0:e);++t=h;m?(i&&(i=je(i)),s=f,a=n.apply(l,o)):i||(i=Ne(r,h))}return m&&c?c=je(c):c||t===v||(c=Ne(u,t)),e&&(m=true,a=n.apply(l,o)),!m||c||i||(o=l=null),a}}function Yt(n){return n}function Zt(n){n||(n={});var t=Ge(n),e=t[0],r=n[e]; -return 1!=t.length||r!==r||Et(r)?function(e){for(var r=t.length,u=false;r--&&(u=ft(e[t[r]],n[t[r]],null,true)););return u}:function(n){return n=n[e],r===n&&(0!==r||1/r==1/n)}}function ne(n,t,e){var r=true,u=t&&xt(t);t&&(e||u.length)||(null==e&&(e=t),o=Y,t=n,n=d,u=xt(t)),false===e?r=false:Et(e)&&"chain"in e&&(r=e.chain);var o=n,i=Ot(o);$t(u,function(e){var u=n[e]=t[e];i&&(o.prototype[e]=function(){var t=this.__chain__,e=this.__wrapped__,i=[e];if(Ee.apply(i,arguments),i=u.apply(n,i),r||t){if(e===i&&Et(i))return this; -i=new o(i),i.__chain__=t}return i})})}function te(){}function ee(n){return function(t){return t[n]}}function re(){return this.__wrapped__}e=e?rt.defaults(Z.Object(),e,rt.pick(Z,F)):Z;var ue=e.Array,oe=e.Boolean,ie=e.Date,ae=e.Function,fe=e.Math,le=e.Number,ce=e.Object,pe=e.RegExp,se=e.String,he=e.TypeError,ve=[],ge=ce.prototype,ye=se.prototype,me=(me=e.window)&&me.document,be=e._,de=ge.toString,_e=pe("^"+se(de).replace(/[.*+?^${}()|[\]\\]/g,"\\$&").replace(/toString|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),we=fe.ceil,je=e.clearTimeout,ke=fe.floor,xe=ae.prototype.toString,Ce=yt(Ce=ce.getPrototypeOf)&&Ce,Oe=ge.hasOwnProperty,Ee=ve.push,Ne=e.setTimeout,Ie=ve.splice,Re=ve.unshift,Se=function(){try{var n={},t=yt(t=ce.defineProperty)&&t,e=t(n,n,n)&&t -}catch(r){}return e}(),Te=yt(Te=ye.contains)&&Te,Ae=yt(Ae=ce.create)&&Ae,De=yt(De=ue.isArray)&&De,$e=e.isFinite,Fe=e.isNaN,Be=yt(Be=ce.keys)&&Be,qe=fe.max,We=fe.min,ze=e.parseInt,Pe=fe.random,Ke={};Ke[q]=ue,Ke[W]=oe,Ke[z]=ie,Ke[P]=ae,Ke[L]=ce,Ke[K]=le,Ke[M]=pe,Ke[V]=se,Y.prototype=d.prototype;var Le=d.support={};Le.funcDecomp=!yt(e.WinRTError)&&D.test(s),Le.funcNames=typeof ae.name=="string";try{Le.dom=11===me.createDocumentFragment().nodeType}catch(Me){Le.dom=false}d.templateSettings={escape:E,evaluate:N,interpolate:I,variable:"",imports:{_:d}},Ae||(et=function(){function n(){}return function(t){if(Et(t)){n.prototype=t; -var r=new n;n.prototype=null}return r||e.Object()}}());var Ve=Se?function(n,t){H.value=t,Se(n,"__bindData__",H)}:te,Ue=De||function(n){return n&&typeof n=="object"&&typeof n.length=="number"&&de.call(n)==q||false},Ge=Be?function(n){return Et(n)?Be(n):[]}:g;Le.dom||(Ct=function(n){return n&&typeof n=="object"&&1===n.nodeType&&!He(n)||false});var He=Ce?function(n){if(!n||de.call(n)!=L)return false;var t=n.valueOf,e=yt(t)&&(e=Ce(t))&&Ce(e);return e?n==e||Ce(n)==e:mt(n)}:mt,Je=st(function(n,t,e){Oe.call(n,e)?n[e]++:n[e]=1 -}),Qe=st(function(n,t,e){(Oe.call(n,e)?n[e]:n[e]=[]).push(t)}),Xe=st(function(n,t,e){n[e]=t}),Ye=Bt,Ze=yt(Ze=ie.now)&&Ze||function(){return(new ie).getTime()},nr=8==ze(_+"08")?ze:function(n,t){return ze(It(n)?n.replace(T,""):n,t||0)};return d.after=function(n,t){if(!Ot(t))throw new he;return function(){return 1>--n?t.apply(this,arguments):void 0}},d.assign=_t,d.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=ue(t);++e=b&&o(r?e[r]:s)))}var p=e[0],v=-1,g=p?p.length:0,y=[];n:for(;++v(m?t(m,h):f(s,h))){for(r=u,(m||s).push(h);--r;)if(m=i[r],0>(m?t(m,h):f(e[r],h)))continue n;y.push(h) -}}for(;u--;)(m=i[u])&&c(m);return l(i),l(s),y},d.invert=function(n,t){for(var e=-1,r=Ge(n),u=r.length,o={};++ee?qe(0,r+e):We(e,r-1))+1);r--;)if(n[r]===t)return r;return-1},d.mixin=ne,d.noConflict=function(){return e._=be,this},d.noop=te,d.now=Ze,d.parseInt=nr,d.random=function(n,t,e){var r=null==n,u=null==t;return null==e&&(u&&typeof n=="boolean"?(e=n,n=1):typeof t=="boolean"&&(e=t,u=true)),r&&u&&(t=1,u=false),n=+n||0,u?(t=n,n=0):t=+t||0,e||n%1||t%1?(e=Pe(),We(n+e*(t-n+parseFloat("1e-"+((e+"").length-1))),t)):ct(n,t) -},d.reduce=Wt,d.reduceRight=zt,d.result=function(n,t){if(n){var e=n[t];return Ot(e)?n[t]():e}},d.runInContext=s,d.size=function(n){var t=n?n.length:0;return typeof t=="number"?t:Ge(n).length},d.some=Kt,d.sortedIndex=Ut,d.template=function(n,t,e){var r=d.templateSettings;n=se(n||""),e=wt({},e,r);var u,o=wt({},e.imports,r.imports),r=Ge(o),o=Rt(o),a=0,f=e.interpolate||A,l="__p+='",f=pe((e.escape||A).source+"|"+f.source+"|"+(f===I?x:A).source+"|"+(e.evaluate||A).source+"|$","g");n.replace(f,function(t,e,r,o,f,c){return r||(r=o),l+=n.slice(a,c).replace($,i),e&&(l+="'+__e("+e+")+'"),f&&(u=true,l+="';"+f+";\n__p+='"),r&&(l+="'+((__t=("+r+"))==null?'':__t)+'"),a=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=ae(r,"return "+l).apply(h,o)}catch(p){throw p.source=l,p}return t?c(t):(c.source=l,c)},d.unescape=function(n){return null==n?"":(n=se(n),0>n.indexOf(";")?n:n.replace(R,bt))},d.uniqueId=function(n){var t=++y; -return se(null==n?"":n)+t},d.all=Tt,d.any=Kt,d.detect=Dt,d.findWhere=Dt,d.foldl=Wt,d.foldr=zt,d.include=St,d.inject=Wt,ne(function(){var n={};return jt(d,function(t,e){d.prototype[e]||(n[e]=t)}),n}(),false),d.first=Lt,d.last=function(n,t,e){var r=0,u=n?n.length:0;if(typeof t!="number"&&null!=t){var o=u;for(t=d.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 p(n,qe(0,u-r))},d.sample=function(n,t,e){return n&&typeof n.length!="number"&&(n=Rt(n)),null==t||e?n?n[ct(0,n.length-1)]:h:(n=Pt(n),n.length=We(qe(0,t),n.length),n) -},d.take=Lt,d.head=Lt,jt(d,function(n,t){var e="sample"!==t;d.prototype[t]||(d.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})}),d.VERSION="2.4.1",d.prototype.chain=function(){return this.__chain__=true,this},d.prototype.toString=function(){return se(this.__wrapped__)},d.prototype.value=re,d.prototype.valueOf=re,$t(["join","pop","shift"],function(n){var t=ve[n];d.prototype[n]=function(){var n=this.__chain__,e=t.apply(this.__wrapped__,arguments); -return n?new Y(e,n):e}}),$t(["push","reverse","sort","unshift"],function(n){var t=ve[n];d.prototype[n]=function(){return t.apply(this.__wrapped__,arguments),this}}),$t(["concat","slice","splice"],function(n){var t=ve[n];d.prototype[n]=function(){return new Y(t.apply(this.__wrapped__,arguments),this.__chain__)}}),d}var h,v=[],g=[],y=0,m=+new Date+"",b=75,d=40,_=" \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/,E=/<%-([\s\S]+?)%>/g,N=/<%([\s\S]+?)%>/g,I=/<%=([\s\S]+?)%>/g,R=/&(?:amp|lt|gt|quot|#39);/g,S=/[&<>"']/g,T=RegExp("^["+_+"]*0+(?=.$)"),A=/($^)/,D=/\bthis\b/,$=/['\n\r\t\u2028\u2029\\]/g,F="Array Boolean Date Function Math Number Object RegExp String _ clearTimeout document isFinite isNaN parseInt setTimeout TypeError window WinRTError".split(" "),B="[object Arguments]",q="[object Array]",W="[object Boolean]",z="[object Date]",P="[object Function]",K="[object Number]",L="[object Object]",M="[object RegExp]",V="[object String]",U={}; -U[P]=false,U[B]=U[q]=U[W]=U[z]=U[K]=U[L]=U[M]=U[V]=true;var G={leading:false,maxWait:0,trailing:false},H={configurable:false,enumerable:false,value:null,writable:false},J={"&":"&","<":"<",">":">",'"':""","'":"'"},Q={"&":"&","<":"<",">":">",""":'"',"'":"'"},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 global]&&global; -!tt||tt.global!==tt&&tt.window!==tt||(Z=tt);var et=(tt=X[typeof module]&&module&&!module.nodeType&&module)&&tt.exports===nt&&nt,rt=s();typeof define=="function"&&typeof define.amd=="object"&&define.amd?(Z._=rt, define(function(){return rt})):nt&&tt?et?(tt.exports=rt)._=rt:nt._=rt:Z._=rt}).call(this); \ No newline at end of file +;(function(){function n(n,t){if(n!==t){if(n>t||typeof n=="undefined")return 1;if(ne?0:e);++r=_&&o===t,l=[]; +if(f){var c=a(r);c?(o=e,r=c):f=false}for(;++uo(r,c)&&l.push(c);return f&&s(r),l}function ft(n,t,e,r){r=(r||0)-1;for(var u=n?n.length:0,o=[];++r=_&&i===t,v=u||h?l():c;for(h&&(v=a(v),i=e);++oi(v,y))&&((u||h)&&v.push(y),c.push(g)) +}return h?(p(v.g),s(v)):u&&p(v),c}function ht(n){return function(t,e,r){var u={};e=m.createCallback(e,r,3),r=-1;var o=t?t.length:0;if(typeof o=="number")for(;++r=r)return false;if(typeof n=="string"||!Ge(n)&&Rt(n))return Ae?Ae.call(n,t,e):-1e?We(0,r+e):e)||0,-1o&&(o=a)}}else t=null==t&&Rt(n)?u:m.createCallback(t,e,3),Ft(n,function(n,e,u){e=t(n,e,u),e>r&&(r=e,o=n)});return o}function zt(n,t,e,r){var u=3>arguments.length;t=m.createCallback(t,r,4);var o=-1,i=n?n.length:0;if(typeof i=="number")for(u&&i&&(e=n[++o]);++oarguments.length;return t=m.createCallback(t,r,4),Bt(n,function(n,r,o){e=u?(u=false,n):t(e,n,r,o) +}),e}function Kt(n){var t=-1,e=n?n.length:0,r=oe(typeof e=="number"?e:0);return Ft(n,function(n){var e=pt(0,++t);r[t]=r[e],r[e]=n}),r}function Lt(n,t,e){var r;t=m.createCallback(t,e,3),e=-1;var u=n?n.length:0;if(typeof u=="number")for(;++er?We(0,u+r):r||0}else if(r)return r=Gt(n,e),n[r]===e?r:-1;return t(n,e,r)}function Ut(n,t,e){if(typeof t!="number"&&null!=t){var r=0,u=-1,o=n?n.length:0;for(t=m.createCallback(t,e,3);++u>>1,e(n[r])e?0:e);++t=g;m?(i&&(i=ke(i)),s=f,a=n.apply(l,o)):i||(i=Ie(r,g))}return m&&c?c=ke(c):c||t===h||(c=Ie(u,t)),e&&(m=true,a=n.apply(l,o)),!m||c||i||(o=l=null),a}}function Zt(n){return n}function ne(n){n||(n={});var t=He(n),e=t[0],r=n[e]; +return 1!=t.length||r!==r||Nt(r)?function(e){for(var r=t.length,u=false;r--&&(u=lt(e[t[r]],n[t[r]],null,true)););return u}:function(n){return n=n[e],r===n&&(0!==r||1/r==1/n)}}function te(n,t,e){var r=true,u=t&&Ct(t);t&&(e||u.length)||(null==e&&(e=t),o=w,t=n,n=m,u=Ct(t)),false===e?r=false:Nt(e)&&"chain"in e&&(r=e.chain);var o=n,i=Et(o);Ft(u,function(e){var u=n[e]=t[e];i&&(o.prototype[e]=function(){var t=this.__chain__,e=this.__wrapped__,i=[e];if(Ne.apply(i,arguments),i=u.apply(n,i),r||t){if(e===i&&Nt(i))return this; +i=new o(i),i.__chain__=t}return i})})}function ee(){}function re(n){return function(t){return t[n]}}function ue(){return this.__wrapped__}n=n?ot.defaults(tt.Object(),n,ot.pick(tt,q)):tt;var oe=n.Array,ie=n.Boolean,ae=n.Date,fe=n.Function,le=n.Math,ce=n.Number,pe=n.Object,se=n.RegExp,he=n.String,ve=n.TypeError,ge=[],ye=pe.prototype,me=he.prototype,be=(be=n.window)&&be.document,de=n._,_e=ye.toString,we=se("^"+he(_e).replace(/[.*+?^${}()|[\]\\]/g,"\\$&").replace(/toString|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),je=le.ceil,ke=n.clearTimeout,xe=le.floor,Ce=fe.prototype.toString,Oe=mt(Oe=pe.getPrototypeOf)&&Oe,Ee=ye.hasOwnProperty,Ne=ge.push,Ie=n.setTimeout,Re=ge.splice,Se=ge.unshift,Te=function(){try{var n={},t=mt(t=pe.defineProperty)&&t,e=t(n,n,n)&&t +}catch(r){}return e}(),Ae=mt(Ae=me.contains)&&Ae,De=mt(De=pe.create)&&De,$e=mt($e=oe.isArray)&&$e,Fe=n.isFinite,Be=n.isNaN,qe=mt(qe=pe.keys)&&qe,We=le.max,ze=le.min,Pe=n.parseInt,Ke=le.random,Le={};Le[z]=oe,Le[P]=ie,Le[K]=ae,Le[L]=fe,Le[V]=pe,Le[M]=ce,Le[U]=se,Le[G]=he,w.prototype=m.prototype;var Me=m.support={};Me.funcDecomp=!mt(n.WinRTError)&&F.test(v),Me.funcNames=typeof fe.name=="string";try{Me.dom=11===be.createDocumentFragment().nodeType}catch(Ve){Me.dom=false}m.templateSettings={escape:I,evaluate:R,interpolate:S,variable:"",imports:{_:m}},De||(rt=function(){function t(){}return function(e){if(Nt(e)){t.prototype=e; +var r=new t;t.prototype=null}return r||n.Object()}}());var Ue=Te?function(n,t){Q.value=t,Te(n,"__bindData__",Q)}:ee,Ge=$e||function(n){return n&&typeof n=="object"&&typeof n.length=="number"&&_e.call(n)==z||false},He=qe?function(n){return Nt(n)?qe(n):[]}:y;Me.dom||(Ot=function(n){return n&&typeof n=="object"&&1===n.nodeType&&!Je(n)||false});var Je=Oe?function(n){if(!n||_e.call(n)!=V)return false;var t=n.valueOf,e=mt(t)&&(e=Oe(t))&&Oe(e);return e?n==e||Oe(n)==e:bt(n)}:bt,Qe=ht(function(n,t,e){Ee.call(n,e)?n[e]++:n[e]=1 +}),Xe=ht(function(n,t,e){(Ee.call(n,e)?n[e]:n[e]=[]).push(t)}),Ye=ht(function(n,t,e){n[e]=t}),Ze=qt,nr=mt(nr=ae.now)&&nr||function(){return(new ae).getTime()},tr=8==Pe(j+"08")?Pe:function(n,t){return Pe(Rt(n)?n.replace(D,""):n,t||0)};return m.after=function(n,t){if(!Et(t))throw new ve;return function(){return 1>--n?t.apply(this,arguments):void 0}},m.assign=wt,m.at=function(n){for(var t=arguments,e=-1,r=ft(t,true,false,1),t=t[2]&&t[2][t[1]]===n?1:r.length,u=oe(t);++e=_&&a(r?n[r]:c)))}var f=n[0],v=-1,g=f?f.length:0,y=[];n:for(;++v(m?e(m,h):i(c,h))){for(r=u,(m||c).push(h);--r;)if(m=o[r],0>(m?e(m,h):i(n[r],h)))continue n;y.push(h) +}}for(;u--;)(m=o[u])&&s(m);return p(o),p(c),y},m.invert=function(n,t){for(var e=-1,r=He(n),u=r.length,o={};++ee?We(0,r+e):ze(e,r-1))+1);r--;)if(n[r]===t)return r;return-1},m.mixin=te,m.noConflict=function(){return n._=de,this},m.noop=ee,m.now=nr,m.parseInt=tr,m.random=function(n,t,e){var r=null==n,u=null==t;return null==e&&(u&&typeof n=="boolean"?(e=n,n=1):typeof t=="boolean"&&(e=t,u=true)),r&&u&&(t=1,u=false),n=+n||0,u?(t=n,n=0):t=+t||0,e||n%1||t%1?(e=Ke(),ze(n+e*(t-n+parseFloat("1e-"+((e+"").length-1))),t)):pt(n,t) +},m.reduce=zt,m.reduceRight=Pt,m.result=function(n,t){if(n){var e=n[t];return Et(e)?n[t]():e}},m.runInContext=v,m.size=function(n){var t=n?n.length:0;return typeof t=="number"?t:He(n).length},m.some=Lt,m.sortedIndex=Gt,m.template=function(n,t,e){var r=m.templateSettings;n=he(n||""),e=jt({},e,r);var u,o=jt({},e.imports,r.imports),r=He(o),o=St(o),i=0,a=e.interpolate||$,l="__p+='",a=se((e.escape||$).source+"|"+a.source+"|"+(a===S?O:$).source+"|"+(e.evaluate||$).source+"|$","g");n.replace(a,function(t,e,r,o,a,c){return r||(r=o),l+=n.slice(i,c).replace(B,f),e&&(l+="'+__e("+e+")+'"),a&&(u=true,l+="';"+a+";\n__p+='"),r&&(l+="'+((__t=("+r+"))==null?'':__t)+'"),i=c+t.length,t +}),l+="';",a=e=e.variable,a||(e="obj",l="with("+e+"){"+l+"}"),l=(u?l.replace(k,""):l).replace(x,"$1").replace(C,"$1;"),l="function("+e+"){"+(a?"":e+"||("+e+"={});")+"var __t,__p='',__e=_.escape"+(u?",__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}":";")+l+"return __p}";try{var c=fe(r,"return "+l).apply(g,o)}catch(p){throw p.source=l,p}return t?c(t):(c.source=l,c)},m.unescape=function(n){return null==n?"":(n=he(n),0>n.indexOf(";")?n:n.replace(T,dt))},m.uniqueId=function(n){var t=++b; +return he(null==n?"":n)+t},m.all=At,m.any=Lt,m.detect=$t,m.findWhere=$t,m.foldl=zt,m.foldr=Pt,m.include=Tt,m.inject=zt,te(function(){var n={};return kt(m,function(t,e){m.prototype[e]||(n[e]=t)}),n}(),false),m.first=Mt,m.last=function(n,t,e){var r=0,u=n?n.length:0;if(typeof t!="number"&&null!=t){var o=u;for(t=m.createCallback(t,e,3);o--&&t(n[o],o,n);)r++}else if(r=t,null==r||e)return n?n[u-1]:g;return h(n,We(0,u-r))},m.sample=function(n,t,e){return n&&typeof n.length!="number"&&(n=St(n)),null==t||e?n?n[pt(0,n.length-1)]:g:(n=Kt(n),n.length=ze(We(0,t),n.length),n) +},m.take=Mt,m.head=Mt,kt(m,function(n,t){var e="sample"!==t;m.prototype[t]||(m.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 w(o,u):o})}),m.VERSION="2.4.1",m.prototype.chain=function(){return this.__chain__=true,this},m.prototype.toString=function(){return he(this.__wrapped__)},m.prototype.value=ue,m.prototype.valueOf=ue,Ft(["join","pop","shift"],function(n){var t=ge[n];m.prototype[n]=function(){var n=this.__chain__,e=t.apply(this.__wrapped__,arguments); +return n?new w(e,n):e}}),Ft(["push","reverse","sort","unshift"],function(n){var t=ge[n];m.prototype[n]=function(){return t.apply(this.__wrapped__,arguments),this}}),Ft(["concat","slice","splice"],function(n){var t=ge[n];m.prototype[n]=function(){return new w(t.apply(this.__wrapped__,arguments),this.__chain__)}}),m}var g,y=[],m=[],b=0,d=+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",k=/\b__p\+='';/g,x=/\b(__p\+=)''\+/g,C=/(__e\(.*?\)|\b__t\))\+'';/g,O=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,E=/\w*$/,N=/^\s*function[ \n\r\t]+\w/,I=/<%-([\s\S]+?)%>/g,R=/<%([\s\S]+?)%>/g,S=/<%=([\s\S]+?)%>/g,T=/&(?:amp|lt|gt|quot|#39);/g,A=/[&<>"']/g,D=RegExp("^["+j+"]*0+(?=.$)"),$=/($^)/,F=/\bthis\b/,B=/['\n\r\t\u2028\u2029\\]/g,q="Array Boolean Date Function Math Number Object RegExp String _ clearTimeout document isFinite isNaN parseInt setTimeout TypeError window WinRTError".split(" "),W="[object Arguments]",z="[object Array]",P="[object Boolean]",K="[object Date]",L="[object Function]",M="[object Number]",V="[object Object]",U="[object RegExp]",G="[object String]",H={}; +H[L]=false,H[W]=H[z]=H[P]=H[K]=H[M]=H[V]=H[U]=H[G]=true;var J={leading:false,maxWait:0,trailing:false},Q={configurable:false,enumerable:false,value:null,writable:false},X={"&":"&","<":"<",">":">",'"':""","'":"'"},Y={"&":"&","<":"<",">":">",""":'"',"'":"'"},Z={"boolean":false,"function":true,object:true,number:false,string:false,undefined:false},nt={"\\":"\\","'":"'","\n":"n","\r":"r","\t":"t","\u2028":"u2028","\u2029":"u2029"},tt=Z[typeof window]&&window||this,et=Z[typeof exports]&&exports&&!exports.nodeType&&exports,rt=Z[typeof global]&&global; +!rt||rt.global!==rt&&rt.window!==rt||(tt=rt);var ut=(rt=Z[typeof module]&&module&&!module.nodeType&&module)&&rt.exports===et&&et,ot=v();typeof define=="function"&&typeof define.amd=="object"&&define.amd?(tt._=ot, define(function(){return ot})):et&&rt?ut?(rt.exports=ot)._=ot:et._=ot:tt._=ot}).call(this); \ No newline at end of file diff --git a/dist/lodash.underscore.js b/dist/lodash.underscore.js index 84f600d60..7c3fd3d24 100644 --- a/dist/lodash.underscore.js +++ b/dist/lodash.underscore.js @@ -113,6 +113,27 @@ /*--------------------------------------------------------------------------*/ + /** + * The base implementation of `compareAscending` used to compare values and + * sort them in ascending order without guaranteeing a stable sort. + * + * @private + * @param {*} a The value to compare to `b`. + * @param {*} b The value to compare to `a`. + * @returns {number} Returns the sort order indicator for `a`. + */ + function baseCompareAscending(a, b) { + if (a !== b) { + if (a > b || typeof a == 'undefined') { + return 1; + } + if (a < b || typeof b == 'undefined') { + return -1; + } + } + return 0; + } + /** * The base implementation of `_.indexOf` without support for binary searches * or `fromIndex` constraints. @@ -136,40 +157,16 @@ } /** - * Used by `sortBy` to compare transformed `collection` elements, stable sorting - * them in ascending order. + * Used by `sortBy` to compare transformed elements of a collection and stable + * sort them in ascending order. * * @private * @param {Object} a The object to compare to `b`. * @param {Object} b The object to compare to `a`. - * @returns {number} Returns the sort order indicator of `1` or `-1`. + * @returns {number} Returns the sort order indicator for `a`. */ function compareAscending(a, b) { - var ac = a.criteria, - bc = b.criteria, - index = -1, - length = ac.length; - - while (++index < length) { - var value = ac[index], - other = bc[index]; - - if (value !== other) { - if (value > other || typeof value == 'undefined') { - return 1; - } - if (value < other || typeof other == 'undefined') { - return -1; - } - } - } - // Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications - // that causes it, under certain circumstances, to return the same value for - // `a` and `b`. See https://github.com/jashkenas/underscore/pull/1247 - // - // This also ensures a stable sort in V8 and other engines. - // See http://code.google.com/p/v8/issues/detail?id=90 - return a.index - b.index; + return baseCompareAscending(a.criteria, b.criteria) || a.index - b.index; } /** @@ -2694,6 +2691,7 @@ result[index] = result[rand]; result[rand] = value; }); + return result; } @@ -2842,7 +2840,7 @@ callback = createCallback(callback, thisArg, 3); forEach(collection, function(value, key, collection) { result[++index] = { - 'criteria': [callback(value, key, collection)], + 'criteria': callback(value, key, collection), 'index': index, 'value': value }; diff --git a/dist/lodash.underscore.min.js b/dist/lodash.underscore.min.js index 451157bcb..271fd0471 100644 --- a/dist/lodash.underscore.min.js +++ b/dist/lodash.underscore.min.js @@ -3,7 +3,7 @@ * Lo-Dash 2.4.1 (Custom Build) lodash.com/license | Underscore.js 1.5.2 underscorejs.org/LICENSE * Build: `lodash underscore exports="amd,commonjs,global,node" -o ./dist/lodash.underscore.js` */ -;(function(){function n(n,t,r){r=(r||0)-1;for(var e=n?n.length:0;++rf||typeof i=="undefined")return 1;if(ir?0:r);++ee||typeof r=="undefined"){r=1;break n}if(rr?0:r);++ee(t,i)&&o.push(i)}return o}function p(n,t,r,e){e=(e||0)-1;for(var u=n?n.length:0,o=[];++ei(a,e)){for(t=r;--t;)if(0>i(n[t],e))continue n;a.push(e)}return a},u.invert=function(n,t){for(var r=-1,e=Lt(n),u=e.length,o={};++rt?0:t);++n b || typeof a == 'undefined') { + return 1; + } + if (a < b || typeof b == 'undefined') { + return -1; + } + } + return 0; + } + /** * The base implementation of `_.indexOf` without support for binary searches * or `fromIndex` constraints. @@ -286,36 +307,42 @@ } /** - * Used by `sortBy` to compare transformed `collection` elements, stable sorting - * them in ascending order. + * Used by `sortBy` to compare transformed elements of a collection and stable + * sort them in ascending order. * * @private * @param {Object} a The object to compare to `b`. * @param {Object} b The object to compare to `a`. - * @returns {number} Returns the sort order indicator of `1` or `-1`. + * @returns {number} Returns the sort order indicator for `a`. */ function compareAscending(a, b) { + return baseCompareAscending(a.criteria, b.criteria) || a.index - b.index; + } + + /** + * Used by `sortBy` to compare multiple properties of each element in a + * collection and stable sort them in ascending order. + * + * @private + * @param {Object} a The object to compare to `b`. + * @param {Object} b The object to compare to `a`. + * @returns {number} Returns the sort order indicator for `a`. + */ + function compareMultipleAscending(a, b) { var ac = a.criteria, bc = b.criteria, index = -1, length = ac.length; while (++index < length) { - var value = ac[index], - other = bc[index]; - - if (value !== other) { - if (value > other || typeof value == 'undefined') { - return 1; - } - if (value < other || typeof other == 'undefined') { - return -1; - } + var result = baseCompareAscending(ac[index], bc[index]); + if (result) { + return result; } } // Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications - // that causes it, under certain circumstances, to return the same value for - // `a` and `b`. See https://github.com/jashkenas/underscore/pull/1247 + // that causes it, under certain circumstances, to provided the same value + // for `a` and `b`. See https://github.com/jashkenas/underscore/pull/1247 // // This also ensures a stable sort in V8 and other engines. // See http://code.google.com/p/v8/issues/detail?id=90 @@ -4274,6 +4301,7 @@ result[index] = result[rand]; result[rand] = value; }); + return result; } @@ -4416,32 +4444,27 @@ */ function sortBy(collection, callback, thisArg) { var index = -1, - isArr = isArray(callback), + multi = callback && isArray(callback), length = collection ? collection.length : 0, result = Array(typeof length == 'number' ? length : 0); - if (!isArr) { + if (!multi) { callback = lodash.createCallback(callback, thisArg, 3); } forEach(collection, function(value, key, collection) { var object = result[++index] = getObject(); - if (isArr) { - object.criteria = map(callback, function(key) { return value[key]; }); - } else { - (object.criteria = getArray())[0] = callback(value, key, collection); - } object.index = index; object.value = value; + object.criteria = multi + ? map(callback, function(key) { return value[key]; }) + : callback(value, key, collection); }); length = result.length; - result.sort(compareAscending); + result.sort(multi ? compareMultipleAscending : compareAscending); while (length--) { var object = result[length]; result[length] = object.value; - if (!isArr) { - releaseArray(object.criteria); - } releaseObject(object); } return result;