diff --git a/dist/lodash.compat.js b/dist/lodash.compat.js index 55d71650d..253e68dde 100644 --- a/dist/lodash.compat.js +++ b/dist/lodash.compat.js @@ -487,34 +487,6 @@ } } - /** - * Slices the `collection` from the `start` index up to, but not including, - * the `end` index. - * - * Note: This function is used instead of `Array#slice` to support node lists - * in IE < 9 and to ensure dense arrays are returned. - * - * @private - * @param {Array|Object|string} collection The collection to slice. - * @param {number} start The start index. - * @param {number} end The end index. - * @returns {Array} Returns the new array. - */ - function slice(array, start, end) { - start || (start = 0); - if (typeof end == 'undefined') { - end = array ? array.length : 0; - } - var index = -1, - length = end - start || 0, - result = Array(length < 0 ? 0 : length); - - while (++index < length) { - result[index] = array[start + index]; - } - return result; - } - /** * Gets the index of the first non-whitespace character of `string`. * @@ -1931,7 +1903,8 @@ // avoid non Object objects, `arguments` objects, and DOM elements if (!(value && toString.call(value) == objectClass) || - (ctor = value.constructor, isFunction(ctor) && !(ctor instanceof ctor)) || + (!hasOwnProperty.call(value, 'constructor') && + (ctor = value.constructor, isFunction(ctor) && !(ctor instanceof ctor))) || (!support.argsClass && isArguments(value)) || (!support.nodeClass && isNode(value))) { return false; @@ -2227,7 +2200,7 @@ return array ? array[0] : undefined; } } - return slice(array, 0, nativeMin(nativeMax(0, n), length)); + return slice(array, 0, n > 0 ? n : 0); } /** @@ -2387,7 +2360,8 @@ } else { n = (callback == null || thisArg) ? 1 : callback || n; } - return slice(array, 0, nativeMin(nativeMax(0, length - n), length)); + n = length - n; + return slice(array, 0, n > 0 ? n : 0); } /** @@ -2522,7 +2496,8 @@ return array ? array[length - 1] : undefined; } } - return slice(array, nativeMax(0, length - n)); + n = length - n; + return slice(array, n > 0 ? n : 0); } /** @@ -2768,12 +2743,55 @@ while (++index < length && callback(array[index], index, array)) { n++; } + } else if (callback == null || thisArg) { + n = 1; } else { - n = (callback == null || thisArg) ? 1 : nativeMax(0, callback); + n = callback > 0 ? callback : 0; } return slice(array, n); } + /** + * Slices `array` from the `start` index up to, but not including, the `end` index. + * + * Note: This function is used instead of `Array#slice` to support node lists + * in IE < 9 and to ensure dense arrays are returned. + * + * @static + * @memberOf _ + * @category Arrays + * @param {Array} array The array to slice. + * @param {number} [start=0] The start index. + * @param {number} [end=array.length] The end index. + * @returns {Array} Returns the new array. + */ + function slice(array, start, end) { + var index = -1, + length = array ? array.length : 0; + + if (typeof start == 'undefined') { + start = 0; + } else if (start < 0) { + start = nativeMax(length + start, 0); + } else if (start > length) { + start = length; + } + if (typeof end == 'undefined') { + end = length; + } else if (end < 0) { + end = nativeMax(length + end, 0); + } else if (end > length) { + end = length; + } + length = end - start || 0; + + var result = Array(length); + while (++index < length) { + result[index] = array[start + index]; + } + return result; + } + /** * 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 @@ -7199,6 +7217,7 @@ lodash.remove = remove; lodash.rest = rest; lodash.shuffle = shuffle; + lodash.slice = slice; lodash.sortBy = sortBy; lodash.tap = tap; lodash.throttle = throttle; @@ -7372,7 +7391,7 @@ }); // add `Array` functions that return new wrapped values - baseEach(['concat', 'slice', 'splice'], function(methodName) { + baseEach(['concat', 'splice'], function(methodName) { var func = arrayRef[methodName]; lodash.prototype[methodName] = function() { return new lodashWrapper(func.apply(this.__wrapped__, arguments), this.__chain__); diff --git a/dist/lodash.compat.min.js b/dist/lodash.compat.min.js index 0beb823c9..734ec5af2 100644 --- a/dist/lodash.compat.min.js +++ b/dist/lodash.compat.min.js @@ -3,61 +3,61 @@ * 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){if(n!==t){if(n>t||typeof n=="undefined")return 1;if(nr?0:r);++ee||13e||8202r||13r||8202=k&&o===t,f=[];if(l){var c=i(e);c?(o=r,e=c):l=false}for(;++uo(e,c)&&f.push(c);return l&&h(e),f}function ct(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(re.unindexedChars&&tr(u)&&(u=u.split(""));++e=k&&a===t,s=u||p?c():f;for(p&&(s=i(s),a=r);++oa(s,y))&&((u||p)&&s.push(y),f.push(v)) -}return p?(g(s.g),h(s)):u&&g(s),f}function mt(n){return function(t,r,u){var o={};if(r=e.createCallback(r,u,3),ce(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,H,jr,Pr,xt,xr,at,te,nt,Cr,Er)}function _t(){var n=(n=e.indexOf)===kt?t:n;return n}function wt(n){return typeof n=="function"&&Sr.test(Rr.call(n))}function jt(n){var t,r;return!n||Er.call(n)!=Y||(t=n.constructor,Yt(t)&&!(t instanceof t))||!re.argsClass&&xt(n)||!re.nodeClass&&s(n)?false:re.ownLast?(fe(n,function(n,t,e){return r=Pr.call(e,t),false}),false!==r):(fe(n,function(n,t){r=t}),typeof r=="undefined"||Pr.call(n,r))}function xt(n){return n&&typeof n=="object"&&typeof n.length=="number"&&Er.call(n)==U||false -}function Ct(n,t,r){var u=0,o=n?n.length:0;if(typeof t!="number"&&null!=t){var a=-1;for(t=e.createCallback(t,r,3);++ae?Xr(0,u+e):e||0}else if(e)return e=Et(n,r),n[e]===r?e:-1;return t(n,r,e)}function Ot(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=e)return false;if(typeof n=="string"||!ce(n)&&tr(n))return Wr?Wr.call(n,t,r):-1r?Xr(0,e+r):r)||0,-1a&&(a=l)}}else t=null==t&&tr(n)?u:e.createCallback(t,r,3),ct(n,function(n,r,e){r=t(n,r,e),r>o&&(o=r,a=n)});return a}function Bt(n,t,r,u){var o=3>arguments.length;if(t=e.createCallback(t,u,4),ce(n)){var a=-1,i=n.length;for(o&&i&&(r=n[++a]);++aarguments.length;return t=e.createCallback(t,u,4),Ft(n,function(n,e,u){r=o?(o=false,n):t(r,n,e,u) -}),r}function zt(n){var t=-1,r=n?n.length:0,e=pr(typeof r=="number"?r:0);return qt(n,function(n){var r=vt(0,++t);e[t]=e[r],e[r]=n}),e}function Kt(n,t,r){var u;if(t=e.createCallback(t,r,3),ce(n)){r=-1;for(var o=n.length;++r=y;m?(u&&(u=Ir(u)),c=a,o=n.apply(i,e)):u||(u=Fr(v,y))}return m&&l?l=Ir(l):l||t===p||(l=Fr(h,t)),r&&(m=true,o=n.apply(i,e)),!m||l||u||(e=i=null),o -}}function Vt(n,t,r){var e=arguments,u=0,o=typeof r=="number"?2:e.length;if(3--n?t.apply(this,arguments):void 0}},e.assign=Vt,e.at=function(n){var t=arguments,r=-1,e=pt(t,true,false,1),t=t[2]&&t[2][t[1]]===n?1:e.length,u=pr(t);for(re.unindexedChars&&tr(n)&&(n=n.split(""));++r=k&&i(e?n[e]:f)))}var l=n[0],s=-1,v=l?l.length:0,y=[];n:for(;++s(m?r(m,p):a(f,p))){for(e=u,(m||f).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])&&h(m);return g(o),g(f),y},e.invert=function(n,t){for(var r=-1,e=se(n),u=e.length,o={};++rt||typeof n=="undefined")return 1;if(ne||13e||8202r||13r||8202=C&&o===t,f=[];if(l){var c=i(e);c?(o=r,e=c):l=false}for(;++uo(e,c)&&f.push(c);return l&&h(e),f}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(re.unindexedChars&&tr(u)&&(u=u.split(""));++e=C&&a===t,s=u||p?c():f;for(p&&(s=i(s),a=r);++oa(s,y))&&((u||p)&&s.push(y),f.push(v))}return p?(g(s.g),h(s)):u&&g(s),f}function yt(n){return function(t,r,u){var o={};if(r=e.createCallback(r,u,3),ce(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;")+"}")(ut,G,jr,Pr,jt,xr,ot,te,Z,Cr,Er) +}function bt(){var n=(n=e.indexOf)===Ct?t:n;return n}function _t(n){return typeof n=="function"&&Sr.test(Rr.call(n))}function wt(n){var t,r;return!n||Er.call(n)!=Q||!Pr.call(n,"constructor")&&(t=n.constructor,Yt(t)&&!(t instanceof t))||!re.argsClass&&jt(n)||!re.nodeClass&&s(n)?false:re.ownLast?(fe(n,function(n,t,e){return r=Pr.call(e,t),false}),false!==r):(fe(n,function(n,t){r=t}),typeof r=="undefined"||Pr.call(n,r))}function jt(n){return n&&typeof n=="object"&&typeof n.length=="number"&&Er.call(n)==M||false}function xt(n,t,r){var u=0,o=n?n.length:0; +if(typeof t!="number"&&null!=t){var a=-1;for(t=e.createCallback(t,r,3);++ae?Xr(0,u+e):e||0}else if(e)return e=Et(n,r),n[e]===r?e:-1;return t(n,r,e)}function kt(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);++ot?t=Xr(u+t,0):t>u&&(t=u),typeof r=="undefined"?r=u:0>r?r=Xr(u+r,0):r>u&&(r=u),u=r-t||0,r=pr(u);++e>>1,r(n[u])r?0:r);++t=e)return false;if(typeof n=="string"||!ce(n)&&tr(n))return Wr?Wr.call(n,t,r):-1r?Xr(0,e+r):r)||0,-1a&&(a=l)}}else t=null==t&&tr(n)?u:e.createCallback(t,r,3),ft(n,function(n,r,e){r=t(n,r,e),r>o&&(o=r,a=n)});return a}function Bt(n,t,r,u){var o=3>arguments.length;if(t=e.createCallback(t,u,4),ce(n)){var a=-1,i=n.length;for(o&&i&&(r=n[++a]);++aarguments.length;return t=e.createCallback(t,u,4),Ft(n,function(n,e,u){r=o?(o=false,n):t(r,n,e,u)}),r}function zt(n){var t=-1,r=n?n.length:0,e=pr(typeof r=="number"?r:0);return qt(n,function(n){var r=ht(0,++t);e[t]=e[r],e[r]=n}),e}function Kt(n,t,r){var u;if(t=e.createCallback(t,r,3),ce(n)){r=-1;for(var o=n.length;++r=y;m?(u&&(u=Ir(u)),c=a,o=n.apply(i,e)):u||(u=Fr(v,y))}return m&&l?l=Ir(l):l||t===p||(l=Fr(h,t)),r&&(m=true,o=n.apply(i,e)),!m||l||u||(e=i=null),o}}function Vt(n,t,r){var e=arguments,u=0,o=typeof r=="number"?2:e.length;if(3--n?t.apply(this,arguments):void 0}},e.assign=Vt,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=pr(t);for(re.unindexedChars&&tr(n)&&(n=n.split(""));++r=C&&i(e?n[e]:f)))}var l=n[0],s=-1,v=l?l.length:0,y=[];n:for(;++s(m?r(m,p):a(f,p))){for(e=u,(m||f).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])&&h(m);return g(o),g(f),y},e.invert=function(n,t){for(var r=-1,e=se(n),u=e.length,o={};++rr?Xr(0,e+r):Gr(r,e-1))+1);e--;)if(n[e]===t)return e;return-1},e.mixin=lr,e.noConflict=function(){return n._=Or,this},e.noop=fr,e.now=ge,e.parseInt=he,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=Jr(),Gr(n+r*(t-n+parseFloat("1e-"+((r+"").length-1))),t)):vt(n,t) -},e.reduce=Bt,e.reduceRight=Wt,e.result=function(n,t){if(n){var r=n[t];return Yt(r)?n[t]():r}},e.runInContext=b,e.size=function(n){var t=n?n.length:0;return typeof t=="number"?t:se(n).length},e.some=Kt,e.sortedIndex=Et,e.template=function(n,t,r){var u=e.templateSettings;n=br(n||""),r=Xt({},r,u);var o,a=Xt({},r.imports,u.imports),u=se(a),a=rr(a),i=0,l=r.interpolate||B,c="__p+='",l=dr((r.escape||B).source+"|"+l.source+"|"+(l===D?q:B).source+"|"+(r.evaluate||B).source+"|$","g");n.replace(l,function(t,r,e,u,a,l){return e||(e=u),c+=n.slice(i,l).replace(z,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(S,""):c).replace(A,"$1").replace(I,"$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=hr(u,"return "+c).apply(_,a)}catch(s){throw s.source=c,s}return t?p(t):(p.source=c,p)},e.trim=er,e.trimLeft=ur,e.trimRight=or,e.unescape=function(n){return null==n?"":(n=br(n),0>n.indexOf(";")?n:n.replace(N,d)) -},e.uniqueId=function(n){var t=++x;return br(null==n?"":n)+t},e.all=Tt,e.any=Kt,e.detect=Dt,e.findWhere=Dt,e.foldl=Bt,e.foldr=Wt,e.include=Rt,e.inject=Bt,lr(function(){var n={};return Gt(e,function(t,r){e.prototype[r]||(n[r]=t)}),n}(),false),e.first=Ct,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]:_;return v(n,Xr(0,o-u))},e.sample=function(n,t,r){return n&&typeof n.length!="number"?n=rr(n):re.unindexedChars&&tr(n)&&(n=n.split("")),null==t||r?n?n[vt(0,n.length-1)]:_:(n=zt(n),n.length=Gr(Xr(0,t),n.length),n) -},e.take=Ct,e.head=Ct,Gt(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 w(o,u):o})}),e.VERSION="2.4.1",e.prototype.chain=function(){return this.__chain__=true,this},e.prototype.toString=function(){return br(this.__wrapped__)},e.prototype.value=Nt,e.prototype.valueOf=Nt,ct(["join","pop","shift"],function(n){var t=wr[n];e.prototype[n]=function(){var n=this.__chain__,r=t.apply(this.__wrapped__,arguments); -return n?new w(r,n):r}}),ct(["push","reverse","sort","unshift"],function(n){var t=wr[n];e.prototype[n]=function(){return t.apply(this.__wrapped__,arguments),this}}),ct(["concat","slice","splice"],function(n){var t=wr[n];e.prototype[n]=function(){return new w(t.apply(this.__wrapped__,arguments),this.__chain__)}}),re.spliceObjects||ct(["pop","shift","splice"],function(n){var t=wr[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 w(u,n):u -}}),e}var _,w=[],j=[],x=0,C=+new Date+"",k=75,O=40,E=" \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",S=/\b__p\+='';/g,A=/\b(__p\+=)''\+/g,I=/(__e\(.*?\)|\b__t\))\+'';/g,N=/&(?:amp|lt|gt|quot|#39);/g,R=/[&<>"']/g,T=/<%-([\s\S]+?)%>/g,P=/<%([\s\S]+?)%>/g,D=/<%=([\s\S]+?)%>/g,q=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,F=/\w*$/,$=/^\s*function[ \n\r\t]+\w/,L=/^0[xX]/,B=/($^)/,W=/\bthis\b/,z=/['\n\r\t\u2028\u2029\\]/g,K="Array Boolean Date Error Function Math Number Object RegExp String _ clearTimeout document isFinite isNaN parseInt setTimeout TypeError window WinRTError".split(" "),M="constructor hasOwnProperty isPrototypeOf propertyIsEnumerable toLocaleString toString valueOf".split(" "),U="[object Arguments]",V="[object Array]",X="[object Boolean]",G="[object Date]",H="[object Error]",J="[object Function]",Q="[object Number]",Y="[object Object]",Z="[object RegExp]",nt="[object String]",tt={}; -tt[J]=false,tt[U]=tt[V]=tt[X]=tt[G]=tt[Q]=tt[Y]=tt[Z]=tt[nt]=true;var rt={leading:false,maxWait:0,trailing:false},et={configurable:false,enumerable:false,value:null,writable:false},ut={"&":"&","<":"<",">":">",'"':""","'":"'"},ot={"&":"&","<":"<",">":">",""":'"',"'":"'"},at={"boolean":false,"function":true,object:true,number:false,string:false,undefined:false},it={"\\":"\\","'":"'","\n":"n","\r":"r","\t":"t","\u2028":"u2028","\u2029":"u2029"},lt=at[typeof window]&&window||this,ft=at[typeof exports]&&exports&&!exports.nodeType&&exports,ct=at[typeof global]&&global; -!ct||ct.global!==ct&&ct.window!==ct||(lt=ct);var pt=(ct=at[typeof module]&&module&&!module.nodeType&&module)&&ct.exports===ft&&ft,st=b();typeof define=="function"&&typeof define.amd=="object"&&define.amd?(lt._=st, define(function(){return st})):ft&&ct?pt?(ct.exports=st)._=st:ft._=st:lt._=st}).call(this); \ No newline at end of file +})},e.remove=function(n,t,r){var u=-1,o=n?n.length:0,a=[];for(t=e.createCallback(t,r,3);++ur?Xr(0,e+r):Gr(r,e-1))+1);e--;)if(n[e]===t)return e;return-1},e.mixin=lr,e.noConflict=function(){return n._=Or,this},e.noop=fr,e.now=ge,e.parseInt=he,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=Jr(),Gr(n+r*(t-n+parseFloat("1e-"+((r+"").length-1))),t)):ht(n,t) +},e.reduce=Bt,e.reduceRight=Wt,e.result=function(n,t){if(n){var r=n[t];return Yt(r)?n[t]():r}},e.runInContext=d,e.size=function(n){var t=n?n.length:0;return typeof t=="number"?t:se(n).length},e.some=Kt,e.sortedIndex=Et,e.template=function(n,t,r){var u=e.templateSettings;n=br(n||""),r=Xt({},r,u);var o,a=Xt({},r.imports,u.imports),u=se(a),a=rr(a),i=0,l=r.interpolate||L,c="__p+='",l=dr((r.escape||L).source+"|"+l.source+"|"+(l===P?D:L).source+"|"+(r.evaluate||L).source+"|$","g");n.replace(l,function(t,r,e,u,a,l){return e||(e=u),c+=n.slice(i,l).replace(W,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(E,""):c).replace(S,"$1").replace(A,"$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=hr(u,"return "+c).apply(b,a)}catch(s){throw s.source=c,s}return t?p(t):(p.source=c,p)},e.trim=er,e.trimLeft=ur,e.trimRight=or,e.unescape=function(n){return null==n?"":(n=br(n),0>n.indexOf(";")?n:n.replace(I,m)) +},e.uniqueId=function(n){var t=++j;return br(null==n?"":n)+t},e.all=Tt,e.any=Kt,e.detect=Dt,e.findWhere=Dt,e.foldl=Bt,e.foldr=Wt,e.include=Rt,e.inject=Bt,lr(function(){var n={};return Gt(e,function(t,r){e.prototype[r]||(n[r]=t)}),n}(),false),e.first=xt,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]:b;return u=o-u,Ot(n,0"']/g,R=/<%-([\s\S]+?)%>/g,T=/<%([\s\S]+?)%>/g,P=/<%=([\s\S]+?)%>/g,D=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,q=/\w*$/,F=/^\s*function[ \n\r\t]+\w/,$=/^0[xX]/,L=/($^)/,B=/\bthis\b/,W=/['\n\r\t\u2028\u2029\\]/g,z="Array Boolean Date Error Function Math Number Object RegExp String _ clearTimeout document isFinite isNaN parseInt setTimeout TypeError window WinRTError".split(" "),K="constructor hasOwnProperty isPrototypeOf propertyIsEnumerable toLocaleString toString valueOf".split(" "),M="[object Arguments]",U="[object Array]",V="[object Boolean]",X="[object Date]",G="[object Error]",H="[object Function]",J="[object Number]",Q="[object Object]",Y="[object RegExp]",Z="[object String]",nt={}; +nt[H]=false,nt[M]=nt[U]=nt[V]=nt[X]=nt[J]=nt[Q]=nt[Y]=nt[Z]=true;var tt={leading:false,maxWait:0,trailing:false},rt={configurable:false,enumerable:false,value:null,writable:false},et={"&":"&","<":"<",">":">",'"':""","'":"'"},ut={"&":"&","<":"<",">":">",""":'"',"'":"'"},ot={"boolean":false,"function":true,object:true,number:false,string:false,undefined:false},at={"\\":"\\","'":"'","\n":"n","\r":"r","\t":"t","\u2028":"u2028","\u2029":"u2029"},it=ot[typeof window]&&window||this,lt=ot[typeof exports]&&exports&&!exports.nodeType&&exports,ft=ot[typeof global]&&global; +!ft||ft.global!==ft&&ft.window!==ft||(it=ft);var ct=(ft=ot[typeof module]&&module&&!module.nodeType&&module)&&ft.exports===lt&<,pt=d();typeof define=="function"&&typeof define.amd=="object"&&define.amd?(it._=pt, define(function(){return pt})):lt&&ft?ct?(ft.exports=pt)._=pt:lt._=pt:it._=pt}).call(this); \ No newline at end of file diff --git a/dist/lodash.js b/dist/lodash.js index 313d86738..e0c25600f 100644 --- a/dist/lodash.js +++ b/dist/lodash.js @@ -464,34 +464,6 @@ } } - /** - * Slices the `collection` from the `start` index up to, but not including, - * the `end` index. - * - * Note: This function is used instead of `Array#slice` to support node lists - * in IE < 9 and to ensure dense arrays are returned. - * - * @private - * @param {Array|Object|string} collection The collection to slice. - * @param {number} start The start index. - * @param {number} end The end index. - * @returns {Array} Returns the new array. - */ - function slice(array, start, end) { - start || (start = 0); - if (typeof end == 'undefined') { - end = array ? array.length : 0; - } - var index = -1, - length = end - start || 0, - result = Array(length < 0 ? 0 : length); - - while (++index < length) { - result[index] = array[start + index]; - } - return result; - } - /** * Gets the index of the first non-whitespace character of `string`. * @@ -1641,7 +1613,8 @@ // avoid non Object objects, `arguments` objects, and DOM elements if (!(value && toString.call(value) == objectClass) || - (ctor = value.constructor, isFunction(ctor) && !(ctor instanceof ctor))) { + (!hasOwnProperty.call(value, 'constructor') && + (ctor = value.constructor, isFunction(ctor) && !(ctor instanceof ctor)))) { return false; } // In most environments an object's own properties are iterated before @@ -1923,7 +1896,7 @@ return array ? array[0] : undefined; } } - return slice(array, 0, nativeMin(nativeMax(0, n), length)); + return slice(array, 0, n > 0 ? n : 0); } /** @@ -2083,7 +2056,8 @@ } else { n = (callback == null || thisArg) ? 1 : callback || n; } - return slice(array, 0, nativeMin(nativeMax(0, length - n), length)); + n = length - n; + return slice(array, 0, n > 0 ? n : 0); } /** @@ -2218,7 +2192,8 @@ return array ? array[length - 1] : undefined; } } - return slice(array, nativeMax(0, length - n)); + n = length - n; + return slice(array, n > 0 ? n : 0); } /** @@ -2464,12 +2439,55 @@ while (++index < length && callback(array[index], index, array)) { n++; } + } else if (callback == null || thisArg) { + n = 1; } else { - n = (callback == null || thisArg) ? 1 : nativeMax(0, callback); + n = callback > 0 ? callback : 0; } return slice(array, n); } + /** + * Slices `array` from the `start` index up to, but not including, the `end` index. + * + * Note: This function is used instead of `Array#slice` to support node lists + * in IE < 9 and to ensure dense arrays are returned. + * + * @static + * @memberOf _ + * @category Arrays + * @param {Array} array The array to slice. + * @param {number} [start=0] The start index. + * @param {number} [end=array.length] The end index. + * @returns {Array} Returns the new array. + */ + function slice(array, start, end) { + var index = -1, + length = array ? array.length : 0; + + if (typeof start == 'undefined') { + start = 0; + } else if (start < 0) { + start = nativeMax(length + start, 0); + } else if (start > length) { + start = length; + } + if (typeof end == 'undefined') { + end = length; + } else if (end < 0) { + end = nativeMax(length + end, 0); + } else if (end > length) { + end = length; + } + length = end - start || 0; + + var result = Array(length); + while (++index < length) { + result[index] = array[start + index]; + } + return result; + } + /** * 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 @@ -6879,6 +6897,7 @@ lodash.remove = remove; lodash.rest = rest; lodash.shuffle = shuffle; + lodash.slice = slice; lodash.sortBy = sortBy; lodash.tap = tap; lodash.throttle = throttle; @@ -7052,7 +7071,7 @@ }); // add `Array` functions that return new wrapped values - forEach(['concat', 'slice', 'splice'], function(methodName) { + forEach(['concat', 'splice'], function(methodName) { var func = arrayRef[methodName]; lodash.prototype[methodName] = function() { return new lodashWrapper(func.apply(this.__wrapped__, arguments), this.__chain__); diff --git a/dist/lodash.min.js b/dist/lodash.min.js index 3a52ae6c3..f54056d4b 100644 --- a/dist/lodash.min.js +++ b/dist/lodash.min.js @@ -3,56 +3,56 @@ * 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){if(n!==t){if(n>t||typeof n=="undefined")return 1;if(nr?0:r);++ee||13e||8202r||13r||8202=x&&o===t,l=[]; -if(f){var c=a(e);c?(o=r,e=c):f=false}for(;++uo(e,c)&&l.push(c);return f&&h(e),l}function ct(n,t,r,e){e=(e||0)-1;for(var u=n?n.length:0,o=[];++e=x&&i===t,v=u||p?c():l;for(p&&(v=a(v),i=r);++oi(v,y))&&((u||p)&&v.push(y),l.push(g)) -}return p?(s(v.g),h(v)):u&&s(v),l}function gt(n){return function(t,r,e){var u={};r=w.createCallback(r,e,3),e=-1;var o=t?t.length:0;if(typeof o=="number")for(;++ee?Pr(0,u+e):e||0}else if(e)return e=xt(n,r),n[e]===r?e:-1;return t(n,r,e)}function kt(n,t,r){if(typeof t!="number"&&null!=t){var e=0,u=-1,o=n?n.length:0;for(t=w.createCallback(t,r,3);++u>>1,r(n[e])r?0:r);++t=e)return false;if(typeof n=="string"||!ee(n)&&Yt(n))return $r?$r.call(n,t,r):-1r?Pr(0,e+r):r)||0,-1o&&(o=a)}}else t=null==t&&Yt(n)?u:w.createCallback(t,r,3),Tt(n,function(n,r,u){r=t(n,r,u),r>e&&(e=r,o=n) -});return o}function Bt(n,t,r,e){var u=3>arguments.length;t=w.createCallback(t,e,4);var o=-1,i=n?n.length:0;if(typeof i=="number")for(u&&i&&(r=n[++o]);++oarguments.length;return t=w.createCallback(t,e,4),Dt(n,function(n,e,o){r=u?(u=false,n):t(r,n,e,o)}),r}function Wt(n){var t=-1,r=n?n.length:0,e=fr(typeof r=="number"?r:0);return Tt(n,function(n){var r=ht(0,++t);e[t]=e[r],e[r]=n}),e}function zt(n,t,r){var e; -t=w.createCallback(t,r,3),r=-1;var u=n?n.length:0;if(typeof u=="number")for(;++r=y;m?(i&&(i=Or(i)),s=f,a=n.apply(l,o)):i||(i=Sr(e,y))}return m&&c?c=Or(c):c||t===h||(c=Sr(u,t)),r&&(m=true,a=n.apply(l,o)),!m||c||i||(o=l=null),a}}function Kt(n,t,r){var e=arguments,u=0,o=typeof r=="number"?2:e.length;if(3--n?t.apply(this,arguments):void 0}},w.assign=Kt,w.at=function(n){for(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);++r=x&&a(e?n[e]:l)))}var f=n[0],v=-1,g=f?f.length:0,y=[];n:for(;++v(m?r(m,p):i(l,p))){for(e=u,(m||l).push(p);--e;)if(m=o[e],0>(m?r(m,p):i(n[e],p)))continue n;y.push(p) -}}for(;u--;)(m=o[u])&&h(m);return s(o),s(l),y},w.invert=function(n,t){for(var r=-1,e=oe(n),u=e.length,o={};++rr?Pr(0,e+r):Kr(r,e-1))+1);e--;)if(n[e]===t)return e;return-1},w.mixin=or,w.noConflict=function(){return n._=jr,this},w.noop=ir,w.now=ie,w.parseInt=ae,w.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(),Kr(n+r*(t-n+parseFloat("1e-"+((r+"").length-1))),t)):ht(n,t) -},w.reduce=Bt,w.reduceRight=qt,w.result=function(n,t){if(n){var r=n[t];return Ht(r)?n[t]():r}},w.runInContext=b,w.size=function(n){var t=n?n.length:0;return typeof t=="number"?t:oe(n).length},w.some=zt,w.sortedIndex=xt,w.template=function(n,t,r){var e=w.templateSettings;n=yr(n||""),r=Mt({},r,e);var u,o=Mt({},r.imports,e.imports),e=oe(o),o=Zt(o),i=0,a=r.interpolate||W,f="__p+='",a=gr((r.escape||W).source+"|"+a.source+"|"+(a===D?F:W).source+"|"+(r.evaluate||W).source+"|$","g");n.replace(a,function(t,r,e,o,a,c){return e||(e=o),f+=n.slice(i,c).replace(L,l),r&&(f+="'+__e("+r+")+'"),a&&(u=true,f+="';"+a+";\n__p+='"),e&&(f+="'+((__t=("+e+"))==null?'':__t)+'"),i=c+t.length,t -}),f+="';",a=r=r.variable,a||(r="obj",f="with("+r+"){"+f+"}"),f=(u?f.replace(A,""):f).replace(E,"$1").replace(N,"$1;"),f="function("+r+"){"+(a?"":r+"||("+r+"={});")+"var __t,__p='',__e=_.escape"+(u?",__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}":";")+f+"return __p}";try{var c=pr(e,"return "+f).apply(d,o)}catch(p){throw p.source=f,p}return t?c(t):(c.source=f,c)},w.trim=nr,w.trimLeft=tr,w.trimRight=rr,w.unescape=function(n){return null==n?"":(n=yr(n),0>n.indexOf(";")?n:n.replace(R,m)) -},w.uniqueId=function(n){var t=++j;return yr(null==n?"":n)+t},w.all=Rt,w.any=zt,w.detect=St,w.findWhere=St,w.foldl=Bt,w.foldr=qt,w.include=Nt,w.inject=Bt,or(function(){var n={};return Ut(w,function(t,r){w.prototype[r]||(n[r]=t)}),n}(),false),w.first=wt,w.last=function(n,t,r){var e=0,u=n?n.length:0;if(typeof t!="number"&&null!=t){var o=u;for(t=w.createCallback(t,r,3);o--&&t(n[o],o,n);)e++}else if(e=t,null==e||r)return n?n[u-1]:d;return v(n,Pr(0,u-e))},w.sample=function(n,t,r){return n&&typeof n.length!="number"&&(n=Zt(n)),null==t||r?n?n[ht(0,n.length-1)]:d:(n=Wt(n),n.length=Kr(Pr(0,t),n.length),n) -},w.take=wt,w.head=wt,Ut(w,function(n,t){var r="sample"!==t;w.prototype[t]||(w.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 C(o,u):o})}),w.VERSION="2.4.1",w.prototype.chain=function(){return this.__chain__=true,this},w.prototype.toString=function(){return yr(this.__wrapped__)},w.prototype.value=Et,w.prototype.valueOf=Et,Tt(["join","pop","shift"],function(n){var t=br[n];w.prototype[n]=function(){var n=this.__chain__,r=t.apply(this.__wrapped__,arguments); -return n?new C(r,n):r}}),Tt(["push","reverse","sort","unshift"],function(n){var t=br[n];w.prototype[n]=function(){return t.apply(this.__wrapped__,arguments),this}}),Tt(["concat","slice","splice"],function(n){var t=br[n];w.prototype[n]=function(){return new C(t.apply(this.__wrapped__,arguments),this.__chain__)}}),w}var d,_=[],w=[],j=0,k=+new Date+"",x=75,C=40,O=" \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",A=/\b__p\+='';/g,E=/\b(__p\+=)''\+/g,N=/(__e\(.*?\)|\b__t\))\+'';/g,R=/&(?:amp|lt|gt|quot|#39);/g,I=/[&<>"']/g,S=/<%-([\s\S]+?)%>/g,T=/<%([\s\S]+?)%>/g,D=/<%=([\s\S]+?)%>/g,F=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,$=/\w*$/,B=/^\s*function[ \n\r\t]+\w/,q=/^0[xX]/,W=/($^)/,z=/\bthis\b/,L=/['\n\r\t\u2028\u2029\\]/g,P="Array Boolean Date Function Math Number Object RegExp String _ clearTimeout document isFinite isNaN parseInt setTimeout TypeError window WinRTError".split(" "),K="[object Arguments]",M="[object Array]",U="[object Boolean]",V="[object Date]",X="[object Function]",G="[object Number]",H="[object Object]",J="[object RegExp]",Q="[object String]",Y={}; -Y[X]=false,Y[K]=Y[M]=Y[U]=Y[V]=Y[G]=Y[H]=Y[J]=Y[Q]=true;var Z={leading:false,maxWait:0,trailing:false},nt={configurable:false,enumerable:false,value:null,writable:false},tt={"&":"&","<":"<",">":">",'"':""","'":"'"},rt={"&":"&","<":"<",">":">",""":'"',"'":"'"},et={"boolean":false,"function":true,object:true,number:false,string:false,undefined:false},ut={"\\":"\\","'":"'","\n":"n","\r":"r","\t":"t","\u2028":"u2028","\u2029":"u2029"},ot=et[typeof window]&&window||this,it=et[typeof exports]&&exports&&!exports.nodeType&&exports,at=et[typeof global]&&global; -!at||at.global!==at&&at.window!==at||(ot=at);var ft=(at=et[typeof module]&&module&&!module.nodeType&&module)&&at.exports===it&&it,lt=b();typeof define=="function"&&typeof define.amd=="object"&&define.amd?(ot._=lt, define(function(){return lt})):it&&at?ft?(at.exports=lt)._=lt:it._=lt:ot._=lt}).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||13e||8202r||13r||8202=k&&o===t,l=[];if(f){var c=a(e);c?(o=r,e=c):f=false}for(;++uo(e,c)&&l.push(c);return f&&h(e),l}function lt(n,t,r,e){e=(e||0)-1;for(var u=n?n.length:0,o=[];++e=k&&i===t,v=u||p?c():l; +for(p&&(v=a(v),i=r);++oi(v,y))&&((u||p)&&v.push(y),l.push(g))}return p?(s(v.g),h(v)):u&&s(v),l}function vt(n){return function(t,r,e){var u={};r=_.createCallback(r,e,3),e=-1;var o=t?t.length:0;if(typeof o=="number")for(;++ee?Pr(0,u+e):e||0}else if(e)return e=xt(n,r),n[e]===r?e:-1;return t(n,r,e)}function jt(n,t,r){if(typeof t!="number"&&null!=t){var e=0,u=-1,o=n?n.length:0; +for(t=_.createCallback(t,r,3);++ut?t=Pr(u+t,0):t>u&&(t=u),typeof r=="undefined"?r=u:0>r?r=Pr(u+r,0):r>u&&(r=u),u=r-t||0,r=fr(u);++e>>1,r(n[e])r?0:r);++t=e)return false;if(typeof n=="string"||!ee(n)&&Yt(n))return $r?$r.call(n,t,r):-1r?Pr(0,e+r):r)||0,-1o&&(o=a)}}else t=null==t&&Yt(n)?u:_.createCallback(t,r,3),Tt(n,function(n,r,u){r=t(n,r,u),r>e&&(e=r,o=n) +});return o}function Bt(n,t,r,e){var u=3>arguments.length;t=_.createCallback(t,e,4);var o=-1,i=n?n.length:0;if(typeof i=="number")for(u&&i&&(r=n[++o]);++oarguments.length;return t=_.createCallback(t,e,4),Dt(n,function(n,e,o){r=u?(u=false,n):t(r,n,e,o)}),r}function Wt(n){var t=-1,r=n?n.length:0,e=fr(typeof r=="number"?r:0);return Tt(n,function(n){var r=st(0,++t);e[t]=e[r],e[r]=n}),e}function zt(n,t,r){var e; +t=_.createCallback(t,r,3),r=-1;var u=n?n.length:0;if(typeof u=="number")for(;++r=y;m?(i&&(i=Or(i)),s=f,a=n.apply(l,o)):i||(i=Sr(e,y))}return m&&c?c=Or(c):c||t===h||(c=Sr(u,t)),r&&(m=true,a=n.apply(l,o)),!m||c||i||(o=l=null),a}}function Kt(n,t,r){var e=arguments,u=0,o=typeof r=="number"?2:e.length;if(3--n?t.apply(this,arguments):void 0}},_.assign=Kt,_.at=function(n){for(var t=arguments,r=-1,e=lt(t,true,false,1),t=t[2]&&t[2][t[1]]===n?1:e.length,u=fr(t);++r=k&&a(e?n[e]:l)))}var f=n[0],v=-1,g=f?f.length:0,y=[];n:for(;++v(m?r(m,p):i(l,p))){for(e=u,(m||l).push(p);--e;)if(m=o[e],0>(m?r(m,p):i(n[e],p)))continue n;y.push(p) +}}for(;u--;)(m=o[u])&&h(m);return s(o),s(l),y},_.invert=function(n,t){for(var r=-1,e=oe(n),u=e.length,o={};++rr?Pr(0,e+r):Kr(r,e-1))+1);e--;)if(n[e]===t)return e;return-1},_.mixin=or,_.noConflict=function(){return n._=jr,this},_.noop=ir,_.now=ie,_.parseInt=ae,_.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(),Kr(n+r*(t-n+parseFloat("1e-"+((r+"").length-1))),t)):st(n,t) +},_.reduce=Bt,_.reduceRight=qt,_.result=function(n,t){if(n){var r=n[t];return Ht(r)?n[t]():r}},_.runInContext=m,_.size=function(n){var t=n?n.length:0;return typeof t=="number"?t:oe(n).length},_.some=zt,_.sortedIndex=xt,_.template=function(n,t,r){var e=_.templateSettings;n=yr(n||""),r=Mt({},r,e);var u,o=Mt({},r.imports,e.imports),e=oe(o),o=Zt(o),i=0,a=r.interpolate||q,f="__p+='",a=gr((r.escape||q).source+"|"+a.source+"|"+(a===T?D:q).source+"|"+(r.evaluate||q).source+"|$","g");n.replace(a,function(t,r,e,o,a,c){return e||(e=o),f+=n.slice(i,c).replace(z,l),r&&(f+="'+__e("+r+")+'"),a&&(u=true,f+="';"+a+";\n__p+='"),e&&(f+="'+((__t=("+e+"))==null?'':__t)+'"),i=c+t.length,t +}),f+="';",a=r=r.variable,a||(r="obj",f="with("+r+"){"+f+"}"),f=(u?f.replace(O,""):f).replace(E,"$1").replace(N,"$1;"),f="function("+r+"){"+(a?"":r+"||("+r+"={});")+"var __t,__p='',__e=_.escape"+(u?",__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}":";")+f+"return __p}";try{var c=pr(e,"return "+f).apply(b,o)}catch(p){throw p.source=f,p}return t?c(t):(c.source=f,c)},_.trim=nr,_.trimLeft=tr,_.trimRight=rr,_.unescape=function(n){return null==n?"":(n=yr(n),0>n.indexOf(";")?n:n.replace(R,y)) +},_.uniqueId=function(n){var t=++w;return yr(null==n?"":n)+t},_.all=At,_.any=zt,_.detect=St,_.findWhere=St,_.foldl=Bt,_.foldr=qt,_.include=Rt,_.inject=Bt,or(function(){var n={};return Ut(_,function(t,r){_.prototype[r]||(n[r]=t)}),n}(),false),_.first=_t,_.last=function(n,t,r){var e=0,u=n?n.length:0;if(typeof t!="number"&&null!=t){var o=u;for(t=_.createCallback(t,r,3);o--&&t(n[o],o,n);)e++}else if(e=t,null==e||r)return n?n[u-1]:b;return e=u-e,kt(n,0"']/g,I=/<%-([\s\S]+?)%>/g,S=/<%([\s\S]+?)%>/g,T=/<%=([\s\S]+?)%>/g,D=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,F=/\w*$/,$=/^\s*function[ \n\r\t]+\w/,B=/^0[xX]/,q=/($^)/,W=/\bthis\b/,z=/['\n\r\t\u2028\u2029\\]/g,L="Array Boolean Date Function Math Number Object RegExp String _ clearTimeout document isFinite isNaN parseInt setTimeout TypeError window WinRTError".split(" "),P="[object Arguments]",K="[object Array]",M="[object Boolean]",U="[object Date]",V="[object Function]",X="[object Number]",G="[object Object]",H="[object RegExp]",J="[object String]",Q={}; +Q[V]=false,Q[P]=Q[K]=Q[M]=Q[U]=Q[X]=Q[G]=Q[H]=Q[J]=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,it=rt[typeof global]&&global; +!it||it.global!==it&&it.window!==it||(ut=it);var at=(it=rt[typeof module]&&module&&!module.nodeType&&module)&&it.exports===ot&&ot,ft=m();typeof define=="function"&&typeof define.amd=="object"&&define.amd?(ut._=ft, define(function(){return ft})):ot&&it?at?(it.exports=ft)._=ft:ot._=ft:ut._=ft}).call(this); \ No newline at end of file diff --git a/dist/lodash.underscore.js b/dist/lodash.underscore.js index b885785e7..8b6227470 100644 --- a/dist/lodash.underscore.js +++ b/dist/lodash.underscore.js @@ -192,34 +192,6 @@ return '\\' + stringEscapes[match]; } - /** - * Slices the `collection` from the `start` index up to, but not including, - * the `end` index. - * - * Note: This function is used instead of `Array#slice` to support node lists - * in IE < 9 and to ensure dense arrays are returned. - * - * @private - * @param {Array|Object|string} collection The collection to slice. - * @param {number} start The start index. - * @param {number} end The end index. - * @returns {Array} Returns the new array. - */ - function slice(array, start, end) { - start || (start = 0); - if (typeof end == 'undefined') { - end = array ? array.length : 0; - } - var index = -1, - length = end - start || 0, - result = Array(length < 0 ? 0 : length); - - while (++index < length) { - result[index] = array[start + index]; - } - return result; - } - /** * Used by `unescape` to convert HTML entities to characters. * @@ -1082,7 +1054,7 @@ return array ? array[0] : undefined; } } - return slice(array, 0, nativeMin(nativeMax(0, n), length)); + return slice(array, 0, n > 0 ? n : 0); } /** @@ -1233,7 +1205,8 @@ } else { n = (callback == null || thisArg) ? 1 : callback || n; } - return slice(array, 0, nativeMin(nativeMax(0, length - n), length)); + n = length - n; + return slice(array, 0, n > 0 ? n : 0); } /** @@ -1351,7 +1324,8 @@ return array ? array[length - 1] : undefined; } } - return slice(array, nativeMax(0, length - n)); + n = length - n; + return slice(array, n > 0 ? n : 0); } /** @@ -1512,12 +1486,55 @@ while (++index < length && callback(array[index], index, array)) { n++; } + } else if (callback == null || thisArg) { + n = 1; } else { - n = (callback == null || thisArg) ? 1 : nativeMax(0, callback); + n = callback > 0 ? callback : 0; } return slice(array, n); } + /** + * Slices `array` from the `start` index up to, but not including, the `end` index. + * + * Note: This function is used instead of `Array#slice` to support node lists + * in IE < 9 and to ensure dense arrays are returned. + * + * @static + * @memberOf _ + * @category Arrays + * @param {Array} array The array to slice. + * @param {number} [start=0] The start index. + * @param {number} [end=array.length] The end index. + * @returns {Array} Returns the new array. + */ + function slice(array, start, end) { + var index = -1, + length = array ? array.length : 0; + + if (typeof start == 'undefined') { + start = 0; + } else if (start < 0) { + start = nativeMax(length + start, 0); + } else if (start > length) { + start = length; + } + if (typeof end == 'undefined') { + end = length; + } else if (end < 0) { + end = nativeMax(length + end, 0); + } else if (end > length) { + end = length; + } + length = end - start || 0; + + var result = Array(length); + while (++index < length) { + result[index] = array[start + index]; + } + return result; + } + /** * 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 diff --git a/dist/lodash.underscore.min.js b/dist/lodash.underscore.min.js index 0eb5ad82e..b5aee30ae 100644 --- a/dist/lodash.underscore.min.js +++ b/dist/lodash.underscore.min.js @@ -3,37 +3,37 @@ * 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,r,t){t=(t||0)-1;for(var e=n?n.length:0;++te||typeof t=="undefined"){t=1;break n}if(tt?0:t);++ee(r,i)&&o.push(i)}return o}function g(n,r,t,e){e=(e||0)-1;for(var u=n?n.length:0,o=[];++eu(f,l))&&(t&&f.push(l),i.push(a))}return i}function y(n){return function(r,t,e){var u={};t=X(t,e,3),e=-1;var o=r?r.length:0;if(typeof o=="number")for(;++ee?Vr(0,u+e):e||0}else if(e)return e=T(r,t),r[e]===t?e:-1;return n(r,t,e)}function x(n,r,t){if(typeof r!="number"&&null!=r){var e=0,o=-1,i=n?n.length:0;for(r=X(r,t,3);++o>>1,t(n[e])u&&(u=t);else r=X(r,t,3),N(n,function(n,t,o){t=r(n,t,o),t>e&&(e=t,u=n)});return u}function R(n,r,t,e){var u=3>arguments.length;r=X(r,e,4);var o=-1,i=n?n.length:0;if(typeof i=="number")for(u&&i&&(t=n[++o]);++oarguments.length;return r=X(r,e,4),q(n,function(n,e,o){t=u?(u=false,n):r(t,n,e,o)}),t}function D(n){var r=-1,t=n?n.length:0,e=Array(typeof t=="number"?t:0);return N(n,function(n){var t;t=++r,t=0+Br(Hr()*(t-0+1)),e[r]=e[t],e[t]=n}),e}function I(n,r,t){var e;r=X(r,t,3),t=-1;var u=n?n.length:0;if(typeof u=="number")for(;++t=y;m?(u&&(u=clearTimeout(u)),c=i,o=n.apply(f,e)):u||(u=setTimeout(h,y))}return m&&a?a=clearTimeout(a):a||r===p||(a=setTimeout(v,r)),t&&(m=true,o=n.apply(f,e)),!m||a||u||(e=f=null),o}}function C(n){if(!n)return n;for(var r=1,t=arguments.length;r"']/g,ar=/($^)/,lr=/['\n\r\t\u2028\u2029\\]/g,cr="[object Arguments]",pr="[object Array]",sr="[object Boolean]",gr="[object Date]",vr="[object Number]",hr="[object Object]",yr="[object RegExp]",mr="[object String]",_r={"&":"&","<":"<",">":">",'"':""","'":"'"},dr={"&":"&","<":"<",">":">",""":'"',"'":"'"},br={"boolean":false,"function":true,object:true,number:false,string:false,undefined:false},wr={"\\":"\\","'":"'","\n":"n","\r":"r","\t":"t","\u2028":"u2028","\u2029":"u2029"},jr=br[typeof window]&&window||this,xr=br[typeof exports]&&exports&&!exports.nodeType&&exports,Tr=br[typeof global]&&global; -!Tr||Tr.global!==Tr&&Tr.window!==Tr||(jr=Tr);var Ar=br[typeof module]&&module&&!module.nodeType&&module,Er=Ar&&Ar.exports===xr&&xr,Or=Array.prototype,Sr=Object.prototype,kr=jr._,Nr=Sr.toString,qr=RegExp("^"+(Nr+"").replace(/[.*+?^${}()|[\]\\]/g,"\\$&").replace(/toString|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),Fr=Math.ceil,Br=Math.floor,Rr=Function.prototype.toString,$r=Sr.hasOwnProperty,Dr=Or.push,Ir=Sr.propertyIsEnumerable,Mr=Or.splice,Wr=d(Wr=Object.create)&&Wr,zr=d(zr=Array.isArray)&&zr,Cr=jr.isFinite,Pr=jr.isNaN,Ur=d(Ur=Object.keys)&&Ur,Vr=Math.max,Gr=Math.min,Hr=Math.random; -f.prototype=i.prototype;var Jr={};!function(){var n={0:1,length:1};Jr.spliceObjects=(Mr.call(n,0,1),!n[0])}(1),i.templateSettings={escape:/<%-([\s\S]+?)%>/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,variable:""},Wr||(l=function(){function n(){}return function(r){if(J(r)){n.prototype=r;var t=new n;n.prototype=null}return t||jr.Object()}}()),b(arguments)||(b=function(n){return n&&typeof n=="object"&&typeof n.length=="number"&&$r.call(n,"callee")&&!Ir.call(n,"callee")||false});var Kr=function(n){var r=[]; -if(!n||!br[typeof n])return r;for(var t in n)$r.call(n,t)&&r.push(t);return r},Lr=y(function(n,r,t){$r.call(n,t)?n[t]++:n[t]=1}),Qr=y(function(n,r,t){$r.call(n,t)?n[t].push(r):n[t]=[r]}),Xr=y(function(n,r,t){n[t]=r}),Yr=F,Zr=function(n,r){if(!n||!br[typeof n])return n;for(var t in n)if(r(n[t],t,n)===ur)break;return n},nt=zr||function(n){return n&&typeof n=="object"&&typeof n.length=="number"&&Nr.call(n)==pr||false};H(/x/)&&(H=function(n){return typeof n=="function"&&"[object Function]"==Nr.call(n)}); -var rt=Ur?function(n){return J(n)?Ur(n):[]}:Kr,tt=d(tt=Date.now)&&tt||function(){return(new Date).getTime()};i.after=function(n,r){if(!H(r))throw new TypeError;return function(){return 1>--n?r.apply(this,arguments):void 0}},i.bind=W,i.bindAll=function(n){for(var r=1i(a,e)){for(r=t;--r;)if(0>i(n[r],e))continue n; -a.push(e)}return a},i.invert=function(n,r){for(var t=-1,e=rt(n),u=e.length,o={};++tr?0:r);++nt?Vr(0,e+t):Gr(t,e-1))+1);e--;)if(n[e]===r)return e; -return-1},i.mixin=nr,i.noConflict=function(){return jr._=kr,this},i.random=function(n,r){return null==n&&null==r&&(r=1),n=+n||0,null==r?(r=n,n=0):r=+r||0,n+Br(Hr()*(r-n+1))},i.reduce=R,i.reduceRight=$,i.result=function(n,r){if(n){var t=n[r];return H(t)?n[r]():t}},i.size=function(n){var r=n?n.length:0;return typeof r=="number"?r:rt(n).length},i.some=I,i.sortedIndex=T,i.template=function(n,r,t){var u=i,o=u.templateSettings;n=(n||"")+"",t=P({},t,o);var f=0,a="__p+='",o=t.variable;n.replace(RegExp((t.escape||ar).source+"|"+(t.interpolate||ar).source+"|"+(t.evaluate||ar).source+"|$","g"),function(r,t,u,o,i){return a+=n.slice(f,i).replace(lr,e),t&&(a+="'+_.escape("+t+")+'"),o&&(a+="';"+o+";\n__p+='"),u&&(a+="'+((__t=("+u+"))==null?'':__t)+'"),f=i+r.length,r -}),a+="';",o||(o="obj",a="with("+o+"||{}){"+a+"}"),a="function("+o+"){var __t,__p='',__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}"+a+"return __p}";try{var l=Function("_","return "+a)(u)}catch(c){throw c.source=a,c}return r?l(r):(l.source=a,l)},i.unescape=function(n){return null==n?"":(n+="",0>n.indexOf(";")?n:n.replace(ir,o))},i.uniqueId=function(n){var r=++er+"";return n?n+r:r},i.all=O,i.any=I,i.detect=k,i.findWhere=function(n,r){return M(n,r,true)},i.foldl=R,i.foldr=$,i.include=E,i.inject=R,i.first=w,i.last=function(n,r,t){var e=0,o=n?n.length:0; -if(typeof r!="number"&&null!=r){var i=o;for(r=X(r,t,3);i--&&r(n[i],i,n);)e++}else if(e=r,null==e||t)return n?n[o-1]:tr;return u(n,Vr(0,o-e))},i.sample=function(n,r,t){return n&&typeof n.length!="number"&&(n=Q(n)),null==r||t?n?n[0+Br(Hr()*(n.length-1-0+1))]:tr:(n=D(n),n.length=Gr(Vr(0,r),n.length),n)},i.take=w,i.head=w,nr(C({},i)),i.VERSION="2.4.1",i.prototype.chain=function(){return this.__chain__=true,this},i.prototype.value=function(){return this.__wrapped__},N("pop push reverse shift sort splice unshift".split(" "),function(n){var r=Or[n]; -i.prototype[n]=function(){var n=this.__wrapped__;return r.apply(n,arguments),Jr.spliceObjects||0!==n.length||delete n[0],this}}),N(["concat","join","slice"],function(n){var r=Or[n];i.prototype[n]=function(){var n=r.apply(this.__wrapped__,arguments);return this.__chain__&&(n=new f(n),n.__chain__=true),n}}),typeof define=="function"&&typeof define.amd=="object"&&define.amd?(jr._=i, define(function(){return i})):xr&&Ar?Er?(Ar.exports=i)._=i:xr._=i:jr._=i}).call(this); \ No newline at end of file +;(function(){function n(n,r,t){t=(t||0)-1;for(var e=n?n.length:0;++te||typeof t=="undefined"){t=1;break n}if(te(r,i)&&o.push(i)}return o}function s(n,r,t,e){e=(e||0)-1; +for(var u=n?n.length:0,o=[];++eu(f,l))&&(t&&f.push(l),i.push(a))}return i}function h(n){return function(r,t,e){var u={};t=X(t,e,3),e=-1;var o=r?r.length:0;if(typeof o=="number")for(;++ee?Vr(0,u+e):e||0}else if(e)return e=T(r,t),r[e]===t?e:-1;return n(r,t,e)}function j(n,r,t){if(typeof r!="number"&&null!=r){var e=0,u=-1,o=n?n.length:0;for(r=X(r,t,3);++ur?r=Vr(u+r,0):r>u&&(r=u),typeof t=="undefined"?t=u:0>t?t=Vr(u+t,0):t>u&&(t=u),u=t-r||0,t=Array(u);++e>>1,t(n[e])u&&(u=t); +else r=X(r,t,3),N(n,function(n,t,o){t=r(n,t,o),t>e&&(e=t,u=n)});return u}function R(n,r,t,e){var u=3>arguments.length;r=X(r,e,4);var o=-1,i=n?n.length:0;if(typeof i=="number")for(u&&i&&(t=n[++o]);++oarguments.length;return r=X(r,e,4),q(n,function(n,e,o){t=u?(u=false,n):r(t,n,e,o)}),t}function D(n){var r=-1,t=n?n.length:0,e=Array(typeof t=="number"?t:0);return N(n,function(n){var t;t=++r,t=0+Br(Hr()*(t-0+1)),e[r]=e[t],e[t]=n +}),e}function I(n,r,t){var e;r=X(r,t,3),t=-1;var u=n?n.length:0;if(typeof u=="number")for(;++t=y;m?(u&&(u=clearTimeout(u)),c=i,o=n.apply(f,e)):u||(u=setTimeout(h,y))}return m&&a?a=clearTimeout(a):a||r===p||(a=setTimeout(v,r)),t&&(m=true,o=n.apply(f,e)),!m||a||u||(e=f=null),o +}}function C(n){if(!n)return n;for(var r=1,t=arguments.length;r"']/g,ar=/($^)/,lr=/['\n\r\t\u2028\u2029\\]/g,cr="[object Arguments]",pr="[object Array]",sr="[object Boolean]",gr="[object Date]",vr="[object Number]",hr="[object Object]",yr="[object RegExp]",mr="[object String]",_r={"&":"&","<":"<",">":">",'"':""","'":"'"},dr={"&":"&","<":"<",">":">",""":'"',"'":"'"},br={"boolean":false,"function":true,object:true,number:false,string:false,undefined:false},wr={"\\":"\\","'":"'","\n":"n","\r":"r","\t":"t","\u2028":"u2028","\u2029":"u2029"},jr=br[typeof window]&&window||this,xr=br[typeof exports]&&exports&&!exports.nodeType&&exports,Tr=br[typeof global]&&global; +!Tr||Tr.global!==Tr&&Tr.window!==Tr||(jr=Tr);var Ar=br[typeof module]&&module&&!module.nodeType&&module,Er=Ar&&Ar.exports===xr&&xr,Or=Array.prototype,Sr=Object.prototype,kr=jr._,Nr=Sr.toString,qr=RegExp("^"+(Nr+"").replace(/[.*+?^${}()|[\]\\]/g,"\\$&").replace(/toString|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),Fr=Math.ceil,Br=Math.floor,Rr=Function.prototype.toString,$r=Sr.hasOwnProperty,Dr=Or.push,Ir=Sr.propertyIsEnumerable,Mr=Or.splice,Wr=_(Wr=Object.create)&&Wr,zr=_(zr=Array.isArray)&&zr,Cr=jr.isFinite,Pr=jr.isNaN,Ur=_(Ur=Object.keys)&&Ur,Vr=Math.max,Gr=Math.min,Hr=Math.random; +i.prototype=o.prototype;var Jr={};!function(){var n={0:1,length:1};Jr.spliceObjects=(Mr.call(n,0,1),!n[0])}(1),o.templateSettings={escape:/<%-([\s\S]+?)%>/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,variable:""},Wr||(a=function(){function n(){}return function(r){if(J(r)){n.prototype=r;var t=new n;n.prototype=null}return t||jr.Object()}}()),d(arguments)||(d=function(n){return n&&typeof n=="object"&&typeof n.length=="number"&&$r.call(n,"callee")&&!Ir.call(n,"callee")||false});var Kr=function(n){var r=[]; +if(!n||!br[typeof n])return r;for(var t in n)$r.call(n,t)&&r.push(t);return r},Lr=h(function(n,r,t){$r.call(n,t)?n[t]++:n[t]=1}),Qr=h(function(n,r,t){$r.call(n,t)?n[t].push(r):n[t]=[r]}),Xr=h(function(n,r,t){n[t]=r}),Yr=F,Zr=function(n,r){if(!n||!br[typeof n])return n;for(var t in n)if(r(n[t],t,n)===ur)break;return n},nt=zr||function(n){return n&&typeof n=="object"&&typeof n.length=="number"&&Nr.call(n)==pr||false};H(/x/)&&(H=function(n){return typeof n=="function"&&"[object Function]"==Nr.call(n)}); +var rt=Ur?function(n){return J(n)?Ur(n):[]}:Kr,tt=_(tt=Date.now)&&tt||function(){return(new Date).getTime()};o.after=function(n,r){if(!H(r))throw new TypeError;return function(){return 1>--n?r.apply(this,arguments):void 0}},o.bind=W,o.bindAll=function(n){for(var r=1i(a,e)){for(r=t;--r;)if(0>i(n[r],e))continue n; +a.push(e)}return a},o.invert=function(n,r){for(var t=-1,e=rt(n),u=e.length,o={};++tr?0:r);++nt?Vr(0,e+t):Gr(t,e-1))+1);e--;)if(n[e]===r)return e; +return-1},o.mixin=nr,o.noConflict=function(){return jr._=kr,this},o.random=function(n,r){return null==n&&null==r&&(r=1),n=+n||0,null==r?(r=n,n=0):r=+r||0,n+Br(Hr()*(r-n+1))},o.reduce=R,o.reduceRight=$,o.result=function(n,r){if(n){var t=n[r];return H(t)?n[r]():t}},o.size=function(n){var r=n?n.length:0;return typeof r=="number"?r:rt(n).length},o.some=I,o.sortedIndex=T,o.template=function(n,r,t){var u=o,i=u.templateSettings;n=(n||"")+"",t=P({},t,i);var f=0,a="__p+='",i=t.variable;n.replace(RegExp((t.escape||ar).source+"|"+(t.interpolate||ar).source+"|"+(t.evaluate||ar).source+"|$","g"),function(r,t,u,o,i){return a+=n.slice(f,i).replace(lr,e),t&&(a+="'+_.escape("+t+")+'"),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)(u)}catch(c){throw c.source=a,c}return r?l(r):(l.source=a,l)},o.unescape=function(n){return null==n?"":(n+="",0>n.indexOf(";")?n:n.replace(ir,u))},o.uniqueId=function(n){var r=++er+"";return n?n+r:r},o.all=O,o.any=I,o.detect=k,o.findWhere=function(n,r){return M(n,r,true)},o.foldl=R,o.foldr=$,o.include=E,o.inject=R,o.first=b,o.last=function(n,r,t){var e=0,u=n?n.length:0; +if(typeof r!="number"&&null!=r){var o=u;for(r=X(r,t,3);o--&&r(n[o],o,n);)e++}else if(e=r,null==e||t)return n?n[u-1]:tr;return e=u-e,x(n,0 0 ? n : 0); } /** @@ -2405,7 +2377,8 @@ } else { n = (callback == null || thisArg) ? 1 : callback || n; } - return slice(array, 0, nativeMin(nativeMax(0, length - n), length)); + n = length - n; + return slice(array, 0, n > 0 ? n : 0); } /** @@ -2540,7 +2513,8 @@ return array ? array[length - 1] : undefined; } } - return slice(array, nativeMax(0, length - n)); + n = length - n; + return slice(array, n > 0 ? n : 0); } /** @@ -2786,12 +2760,55 @@ while (++index < length && callback(array[index], index, array)) { n++; } + } else if (callback == null || thisArg) { + n = 1; } else { - n = (callback == null || thisArg) ? 1 : nativeMax(0, callback); + n = callback > 0 ? callback : 0; } return slice(array, n); } + /** + * Slices `array` from the `start` index up to, but not including, the `end` index. + * + * Note: This function is used instead of `Array#slice` to support node lists + * in IE < 9 and to ensure dense arrays are returned. + * + * @static + * @memberOf _ + * @category Arrays + * @param {Array} array The array to slice. + * @param {number} [start=0] The start index. + * @param {number} [end=array.length] The end index. + * @returns {Array} Returns the new array. + */ + function slice(array, start, end) { + var index = -1, + length = array ? array.length : 0; + + if (typeof start == 'undefined') { + start = 0; + } else if (start < 0) { + start = nativeMax(length + start, 0); + } else if (start > length) { + start = length; + } + if (typeof end == 'undefined') { + end = length; + } else if (end < 0) { + end = nativeMax(length + end, 0); + } else if (end > length) { + end = length; + } + length = end - start || 0; + + var result = Array(length); + while (++index < length) { + result[index] = array[start + index]; + } + return result; + } + /** * 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 @@ -7219,6 +7236,7 @@ lodash.remove = remove; lodash.rest = rest; lodash.shuffle = shuffle; + lodash.slice = slice; lodash.sortBy = sortBy; lodash.tap = tap; lodash.throttle = throttle; @@ -7392,7 +7410,7 @@ }); // add `Array` functions that return new wrapped values - baseEach(['concat', 'slice', 'splice'], function(methodName) { + baseEach(['concat', 'splice'], function(methodName) { var func = arrayRef[methodName]; lodash.prototype[methodName] = function() { return new lodashWrapper(func.apply(this.__wrapped__, arguments), this.__chain__); diff --git a/test/test.js b/test/test.js index 2de7f3155..4caddeae0 100644 --- a/test/test.js +++ b/test/test.js @@ -1234,12 +1234,11 @@ }); test('should work with ' + key + ' and a `fromIndex` >= `collection.length`', 6, function() { - strictEqual(_.contains(collection, 1, 6), false); - strictEqual(_.contains(collection, undefined, 6), false); - strictEqual(_.contains(collection, '', 6), false); - strictEqual(_.contains(collection, 1, 8), false); - strictEqual(_.contains(collection, undefined, 8), false); - strictEqual(_.contains(collection, '', 8), false); + _.forEach([6, 8], function(fromIndex) { + strictEqual(_.contains(collection, 1, fromIndex), false); + strictEqual(_.contains(collection, undefined, fromIndex), false); + strictEqual(_.contains(collection, '', fromIndex), false); + }); }); test('should work with ' + key + ' and a negative `fromIndex`', 1, function() { @@ -2599,7 +2598,7 @@ Bar.prototype.constructor = Bar; var keys = []; - func(shadowedObject, function(value, key) { keys.push(key); }); + func(new Bar, function(value, key) { keys.push(key); }); deepEqual(keys.sort(), shadowedProps); }); }); @@ -3180,11 +3179,12 @@ equal(_.indexOf(array, 1, 2), 3); }); - test('should work with `fromIndex` >= `array.length`', 4, function() { - equal(_.indexOf(array, 1, 6), -1); - equal(_.indexOf(array, undefined, 6), -1); - equal(_.indexOf(array, 1, 8), -1); - equal(_.indexOf(array, undefined, 8), -1); + test('should work with `fromIndex` >= `array.length`', 6, function() { + _.forEach([6, 8], function(fromIndex) { + equal(_.indexOf(array, 1, fromIndex), -1); + equal(_.indexOf(array, undefined, fromIndex), -1); + equal(_.indexOf(array, '', fromIndex), -1); + }); }); test('should work with a negative `fromIndex`', 1, function() { @@ -4940,11 +4940,12 @@ strictEqual(_.lastIndexOf(array, 1, 2), 0); }); - test('should work with `fromIndex` >= `array.length`', 4, function() { - equal(_.lastIndexOf(array, undefined, 6), -1); - equal(_.lastIndexOf(array, 1, 6), 3); - equal(_.lastIndexOf(array, undefined, 8), -1); - equal(_.lastIndexOf(array, 1, 8), 3); + test('should work with `fromIndex` >= `array.length`', 6, function() { + _.forEach([6, 8], function(fromIndex) { + equal(_.lastIndexOf(array, undefined, fromIndex), -1); + equal(_.lastIndexOf(array, 1, fromIndex), 3); + equal(_.lastIndexOf(array, '', fromIndex), -1); + }); }); test('should work with a negative `fromIndex`', 1, function() { @@ -6912,6 +6913,55 @@ }); }(1, 2, 3)); + + /*--------------------------------------------------------------------------*/ + + QUnit.module('lodash.slice'); + + (function() { + var array = [1, 2, 3]; + + test('should work with a positive `start`', 1, function() { + deepEqual(_.slice(array, 1), [2, 3]); + }); + + test('should work with a `start` >= `array.length`', 2, function() { + _.forEach([3, 4], function(start) { + deepEqual(_.slice(array, start), []); + }); + }); + + test('should work with a negative `start`', 1, function() { + deepEqual(_.slice(array, -1), [3]); + }); + + test('should work with a negative `start` <= negative `array.length`', 2, function() { + _.forEach([-3, -4], function(start) { + deepEqual(_.slice(array, start), [1, 2, 3]); + }); + }); + + test('should work with a positive `end`', 1, function() { + deepEqual(_.slice(array, 0, 1), [1]); + }); + + test('should work with a `end` >= `array.length`', 2, function() { + _.forEach([3, 4], function(end) { + deepEqual(_.slice(array, 0, end), [1, 2, 3]); + }); + }); + + test('should work with a negative `end`', 1, function() { + deepEqual(_.slice(array, 0, -1), [1, 2]); + }); + + test('should work with a negative `end` <= negative `array.length`', 2, function() { + _.forEach([-3, -4], function(end) { + deepEqual(_.slice(array, 0, end), []); + }); + }); + }()); + /*--------------------------------------------------------------------------*/ QUnit.module('lodash.some'); @@ -7828,14 +7878,34 @@ QUnit.module('lodash.toArray'); (function() { - var args = arguments, - array = [1, 2, 3]; + test('should return the values of objects', 1, function() { + var array = [1, 2, 3], + object = { 'a': 1, 'b': 2, 'c': 3 }; + + deepEqual(_.toArray(object), array); + }); + + test('should work with a string for `collection` (test in Opera < 10.52)', 2, function() { + deepEqual(_.toArray('abc'), ['a', 'b', 'c']); + deepEqual(_.toArray(Object('abc')), ['a', 'b', 'c']); + }); + }()); + + + /*--------------------------------------------------------------------------*/ + + QUnit.module('lodash.slice and lodash.toArray'); + + _.forEach(['slice', 'toArray'], function(methodName) { + var args = (function() { return arguments; }(1, 2, 3)), + array = [1, 2, 3], + func = _[methodName]; test('should return a dense array', 3, function() { var sparse = Array(3); sparse[1] = 2; - var actual = _.toArray(sparse); + var actual = func(sparse); ok(0 in actual); ok(2 in actual); @@ -7844,38 +7914,28 @@ test('should treat array-like objects like arrays', 2, function() { var object = { '0': 'a', '1': 'b', '2': 'c', 'length': 3 }; - deepEqual(_.toArray(object), ['a', 'b', 'c']); - deepEqual(_.toArray(args), array); + deepEqual(func(object), ['a', 'b', 'c']); + deepEqual(func(args), array); }); test('should return a shallow clone of arrays', 2, function() { - var actual = _.toArray(array); + var actual = func(array); notStrictEqual(actual, array); - deepEqual(_.toArray(array), array); - }); - - test('should return the values of objects', 1, function() { - var object = { 'a': 1, 'b': 2, 'c': 3 }; - deepEqual(_.toArray(object), array); - }); - - test('should work with a string for `collection` (test in Opera < 10.52)', 2, function() { - deepEqual(_.toArray('abc'), ['a', 'b', 'c']); - deepEqual(_.toArray(Object('abc')), ['a', 'b', 'c']); + deepEqual(func(array), array); }); test('should work with a node list for `collection` (test in IE < 9)', 1, function() { if (document) { try { var nodeList = document.getElementsByTagName('body'), - actual = _.toArray(nodeList); + actual = func(nodeList); } catch(e) { } deepEqual(actual, [body]); } else { skipTest(); } }); - }(1, 2, 3)); + }); /*--------------------------------------------------------------------------*/ @@ -8885,7 +8945,7 @@ var acceptFalsey = _.difference(allMethods, rejectFalsey); - test('should accept falsey arguments', 162, function() { + test('should accept falsey arguments', 163, function() { var emptyArrays = _.map(falsey, function() { return []; }), isExposed = '_' in root, oldDash = root._;