diff --git a/dist/lodash.compat.js b/dist/lodash.compat.js index a2d104e8b..17794596c 100644 --- a/dist/lodash.compat.js +++ b/dist/lodash.compat.js @@ -2296,6 +2296,9 @@ * @returns {Array} Returns the slice of `array`. * @example * + * _.drop([1, 2, 3], 1); + * // => [2, 3] + * * _.drop([1, 2, 3], 2); * // => [3] * @@ -2308,9 +2311,79 @@ var drop = rest; /** - * Creates an array with elements dropped from the beginning of `array` as - * long as the predicate returns truthy. The predicate is bound to `thisArg` - * and invoked with three arguments; (value, index, array). + * Creates an array with `n` elements dropped from the end of `array`. + * + * @static + * @memberOf _ + * @type Function + * @category Arrays + * @param {Array} array The array to query. + * @param {number} [n=1] The number of elements to drop. + * @returns {Array} Returns the slice of `array`. + * @example + * + * _.dropRight([1, 2, 3], 1); + * // => [1, 2] + * + * _.dropRight([1, 2, 3], 2); + * // => [1] + * + * _.dropRight([1, 2, 3], 5); + * // => [] + * + * _.dropRight([1, 2, 3], 0); + * // => [1, 2, 3] + */ + var dropRight = initial; + + /** + * Creates an array of elements excluding those dropped from the end of `array`. + * Elements will be dropped until the predicate returns falsey. The predicate + * is bound to `thisArg`nand invoked with three arguments; (value, index, array). + * + * If a property name is provided for `predicate` the created "_.pluck" style + * callback will return the property value of the given element. + * + * If an object is provided for `predicate` the created "_.where" style callback + * will return `true` for elements that have the properties of the given object, + * else `false`. + * + * @static + * @memberOf _ + * @type Function + * @category Arrays + * @param {Array} array The array to query. + * @param {Function|Object|string} [predicate=identity] The function called + * per element. + * @returns {Array} Returns the slice of `array`. + * @example + * + * _.dropRightWhile([1, 2, 3], function(num) { + * return num > 1; + * }); + * // => [1] + * + * var characters = [ + * { 'name': 'barney', 'employer': 'slate' }, + * { 'name': 'fred', 'employer': 'slate', 'blocked': true }, + * { 'name': 'pebbles', 'employer': 'na', 'blocked': true } + * ]; + * + * // using "_.pluck" callback shorthand + * _.pluck(_.dropRightWhile(characters, 'blocked'), 'name'); + * // => ['barney'] + * + * // using "_.where" callback shorthand + * _.pluck(_.dropRightWhile(characters, { 'employer': 'na' }), 'name'); + * // => ['barney', 'fred'] + */ + var dropRightWhile = initial; + + /** + * Creates an array of elements excluding those dropped from the beginning + * of `array`. Elements will be dropped until the predicate returns falsey. + * The predicate is bound to `thisArg` and invoked with three arguments; + * (value, index, array). * * If a property name is provided for `predicate` the created "_.pluck" style * callback will return the property value of the given element. @@ -3040,21 +3113,93 @@ * @returns {Array} Returns the slice of `array`. * @example * + * _.take([1, 2, 3], 1); + * // => [2] + * * _.take([1, 2, 3], 2); * // => [1, 2] * * _.take([1, 2, 3], 5); * // => [1, 2, 3] * - * _.take([1, 2, 3], -1); + * _.take([1, 2, 3], 0); * // => [] */ var take = first; /** - * Creates an array of elements from the beginning of `array` while the - * predicate returns truthy. The predicate is bound to `thisArg` and invoked - * with three arguments; (value, index, array). + * Creates an array of the last `n` elements of `array`. + * + * @static + * @memberOf _ + * @type Function + * @category Arrays + * @param {Array} array The array to query. + * @param {number} [n=1] The number of elements to take. + * @returns {Array} Returns the slice of `array`. + * @example + * + * _.takeRight([1, 2, 3], 1); + * // => [3] + * + * _.takeRight([1, 2, 3], 2); + * // => [2, 3] + * + * _.takeRight([1, 2, 3], 5); + * // => [1, 2, 3] + * + * _.takeRight([1, 2, 3], 0); + * // => [] + */ + var takeRight = last; + + /** + * Creates an array of elements from the end of `array`. Elements will be + * taken until the predicate returns falsey. The predicate is bound to `thisArg` + * and invoked with three arguments; (value, index, array). + * + * If a property name is provided for `predicate` the created "_.pluck" style + * callback will return the property value of the given element. + * + * If an object is provided for `predicate` the created "_.where" style callback + * will return `true` for elements that have the properties of the given object, + * else `false`. + * + * @static + * @memberOf _ + * @type Function + * @category Arrays + * @param {Array} array The array to query. + * @param {Function|Object|string} [predicate=identity] The function called + * per element. + * @returns {Array} Returns the slice of `array`. + * @example + * + * _.takeRightWhile([1, 2, 3], function(num) { + * return num > 1; + * }); + * // => [2, 3] + * + * var characters = [ + * { 'name': 'barney', 'employer': 'slate' }, + * { 'name': 'fred', 'employer': 'slate', 'blocked': true }, + * { 'name': 'pebbles', 'employer': 'na', 'blocked': true } + * ]; + * + * // using "_.pluck" callback shorthand + * _.pluck(_.takeRightWhile(characters, 'blocked'), 'name'); + * // => ['fred', 'pebbles'] + * + * // using "_.where" callback shorthand + * _.pluck(_.takeRightWhile(characters, { 'employer': 'na' }), 'name'); + * // => ['pebbles'] + */ + var takeRightWhile = last; + + /** + * Creates an array of elements from the beginning of `array`. Elements will + * be taken until the predicate returns falsey. The predicate is bound to + * `thisArg` and invoked with three arguments; (value, index, array). * * If a property name is provided for `predicate` the created "_.pluck" style * callback will return the property value of the given element. @@ -7940,6 +8085,8 @@ lodash.delay = delay; lodash.difference = difference; lodash.drop = drop; + lodash.dropRight = dropRight; + lodash.dropRightWhile = dropRightWhile; lodash.dropWhile = dropWhile; lodash.filter = filter; lodash.flatten = flatten; @@ -8106,6 +8253,8 @@ lodash.last = last; lodash.sample = sample; lodash.take = first; + lodash.takeRight = last; + lodash.takeRightWhile = last; lodash.takeWhile = first; // add aliases diff --git a/dist/lodash.compat.min.js b/dist/lodash.compat.min.js index 29b493310..66957d0fe 100644 --- a/dist/lodash.compat.min.js +++ b/dist/lodash.compat.min.js @@ -6,63 +6,64 @@ ;(function(){function n(n,t){if(n!==t){if(n>t||typeof n=="undefined")return 1;if(ne||13e||8202r||13r||8202a(e,l)&&f.push(l);return f}function st(n,t){var r=-1,e=n,u=n?n.length:0;if(typeof u=="number")for(se.unindexedChars&&lr(e)&&(e=e.split(""));++ri(s,g)&&((u||f)&&s.push(g),c.push(p))}return c}function xt(n,t,r){for(var e=t.length,u=-1,o=te(r.length-e,0),a=-1,i=n.length,l=dr(o+i);++ar&&(r=0),s&&(a=[]),p&&(i=[]),g=[n,t,r,e,u,o,a,i],t==w||t==(w|k)?f(g):X(g))}function Ot(n){n.d=H;var t=wr,r="return function("+n.a+"){",e="var r="+n.b+";if(!j(p)){return r}";se.nonEnumArgs&&(e+="var m=p.length;if(m&&i(p)){l=-1;while(++lu;u++)e+="l='"+n.d[u]+"';if((!(k&&n[l])&&g.call(p,l))",n.e||(e+="||(!n[l]&&p[l]!==q[l])"),e+="){"+n.c+"}";e+="}"}return t("e,f,g,i,j,q,o,u,v,w",r+(e+"return r;")+"}")(tt,Sr,Br,It,or,Ir,ce,at,Rr,Lr) -}function Et(){var n=(n=u.indexOf)===Nt?t:n;return n}function At(n){return typeof n=="function"&&Pr.test($r.call(n))}function St(n){var t,r;return!n||Lr.call(n)!=ut||!Br.call(n,"constructor")&&(t=n.constructor,ur(t)&&!(t instanceof t))||!se.argsClass&&It(n)||!se.nodeClass&&p(n)?false:se.ownLast?(he(n,function(n,t,e){return r=Br.call(e,t),false}),false!==r):(he(n,function(n,t){r=t}),typeof r=="undefined"||Br.call(n,r))}function It(n){return n&&typeof n=="object"&&typeof n.length=="number"&&Lr.call(n)==J||false -}function Rt(n,t,r){if(typeof t!="number"&&null!=t){var e=-1,o=n?n.length:0,a=0;for(t=u.createCallback(t,r,3);++ee?te(0,u+e):e||0;else if(e)return e=Pt(n,r),u&&n[e]===r?e:-1;return t(n,r,e)}function Tt(n,t,r){if(typeof t!="number"&&null!=t){var e=-1,o=n?n.length:0,a=0;for(t=u.createCallback(t,r,3);++et?t=te(u+t,0):t>u&&(t=u),typeof r=="undefined"?r=u:0>r?r=te(u+r,0):r>u&&(r=u),u=r-t||0,r=dr(u);++e>>1,r(n[e])r?0:r);++t=e)return false;if(typeof n=="string"||!we(n)&&lr(n))return Gr?Gr.call(n,t,r):-1r?te(0,e+r):r)||0,-1a&&(a=l)}else t=null==t&&lr(n)?e:u.createCallback(t,r,3),st(n,function(n,r,e){r=t(n,r,e),r>o&&(o=r,a=n)});return a}function Yt(n,t,r,e){var o=3>arguments.length;if(t=u.createCallback(t,e,4),we(n)){var a=-1,i=n.length;for(o&&i&&(r=n[++a]);++aarguments.length;return t=u.createCallback(t,e,4),pt(n,function(n,e,u){r=o?(o=false,n):t(r,n,e,u)}),r}function Ht(n){var t=-1,r=n?n.length:0,e=dr(typeof r=="number"?r:0);return st(n,function(n){var r=_t(0,++t);e[t]=e[r],e[r]=n}),e}function Jt(n,t,r){var e;if(t=u.createCallback(t,r,3),we(n)){r=-1;for(var o=n.length;++rarguments.length)return kt(n,w,null,t); -if(n)var r=n[A]?n[A][2]:n.length,e=Lt(arguments,2),r=r-e.length;return kt(n,w|k,r,t,e)}function Zt(n,t,r){var e,u,o,a,i,l,f,c=0,s=false,p=true;if(!ur(n))throw new Er;if(t=0=r||r>t?(u&&Wr(u),r=f,u=l=f=_,r&&(c=Ie(),o=n.apply(i,e),l||u||(e=i=null))):l=Mr(h,r)},v=function(){l&&Wr(l),u=l=f=_,(p||s!==t)&&(c=Ie(),o=n.apply(i,e),l||u||(e=i=null))};return function(){if(e=arguments,a=Ie(),i=this,f=p&&(l||!g),false===s)var r=g&&!l; -else{u||g||(c=a);var y=s-(a-c),m=0>=y||y>s;m?(u&&(u=Wr(u)),c=a,o=n.apply(i,e)):u||(u=Mr(v,y))}return m&&l?l=Wr(l):l||t===s||(l=Mr(h,t)),r&&(m=true,o=n.apply(i,e)),!m||l||u||(e=i=null),o}}function nr(n,t,r){var e=arguments,u=0,o=e.length,a=typeof r;if("number"!=a&&"string"!=a||!e[3]||e[3][r]!==t||(o=2),3t||null==n)return r;for(n=Or(n);0--n?t.apply(this,arguments):void 0}},u.assign=nr,u.at=function(n,t){var r=arguments,e=-1,u=gt(r,true,false,1),o=u.length,a=typeof t;for("number"!=a&&"string"!=a||!r[2]||r[2][t]!==n||(o=1),se.unindexedChars&&lr(n)&&(n=n.split("")),r=dr(o);++earguments.length?kt(t,w|x,null,n):kt(t,w|x|k,null,n,Lt(arguments,2))},u.chain=function(n){return n=new o(n),n.__chain__=true,n},u.compact=function(n){for(var t=-1,r=n?n.length:0,e=0,u=[];++t(g?r(g,f):a(l,f))){for(e=u,(g||l).push(f);--e;)if(g=o[e],0>(g?r(g,f):a(n[e],f)))continue n;p.push(f)}}return p},u.invert=function(n,t){for(var r=-1,e=Ce(n),u=e.length,o={};++rarguments.length&&we(n))for(;++ra(e,l)&&f.push(l);return f}function st(n,t){var r=-1,e=n,u=n?n.length:0;if(typeof u=="number")for(ge.unindexedChars&&cr(e)&&(e=e.split(""));++ri(s,g)&&((u||f)&&s.push(g),c.push(p))}return c}function xt(n,t,r){for(var e=t.length,u=-1,o=ee(r.length-e,0),a=-1,i=n.length,l=_r(o+i);++ar&&(r=0),s&&(a=[]),p&&(i=[]),g=[n,t,r,e,u,o,a,i],t==w||t==(w|k)?f(g):X(g))}function Ot(n){n.d=H;var t=Cr,r="return function("+n.a+"){",e="var r="+n.b+";if(!j(p)){return r}";ge.nonEnumArgs&&(e+="var m=p.length;if(m&&i(p)){l=-1;while(++lu;u++)e+="l='"+n.d[u]+"';if((!(k&&n[l])&&g.call(p,l))",n.e||(e+="||(!n[l]&&p[l]!==q[l])"),e+="){"+n.c+"}";e+="}"}return t("e,f,g,i,j,q,o,u,v,w",r+(e+"return r;")+"}")(tt,Rr,Ur,It,ir,Nr,pe,at,Tr,Wr) +}function Et(){var n=(n=u.indexOf)===Nt?t:n;return n}function At(n){return typeof n=="function"&&Fr.test(Br.call(n))}function St(n){var t,r;return!n||Wr.call(n)!=ut||!Ur.call(n,"constructor")&&(t=n.constructor,ar(t)&&!(t instanceof t))||!ge.argsClass&&It(n)||!ge.nodeClass&&p(n)?false:ge.ownLast?(ye(n,function(n,t,e){return r=Ur.call(e,t),false}),false!==r):(ye(n,function(n,t){r=t}),typeof r=="undefined"||Ur.call(n,r))}function It(n){return n&&typeof n=="object"&&typeof n.length=="number"&&Wr.call(n)==J||false +}function Rt(n,t,r){if(typeof t!="number"&&null!=t){var e=-1,o=n?n.length:0,a=0;for(t=u.createCallback(t,r,3);++ee?ee(0,u+e):e||0;else if(e)return e=Ft(n,r),u&&n[e]===r?e:-1;return t(n,r,e)}function Tt(n,t,r){var e=n?n.length:0;if(typeof t!="number"&&null!=t){var o=e,a=0;for(t=u.createCallback(t,r,3);o--&&t(n[o],o,n);)a++}else a=null==t||r?1:t;return a=e-a,Wt(n,0,0t?t=ee(u+t,0):t>u&&(t=u),typeof r=="undefined"?r=u:0>r?r=ee(u+r,0):r>u&&(r=u),u=r-t||0,r=_r(u);++e>>1,r(n[e])r?0:r);++t=e)return false;if(typeof n=="string"||!Ce(n)&&cr(n))return Jr?Jr.call(n,t,r):-1r?ee(0,e+r):r)||0,-1a&&(a=l)}else t=null==t&&cr(n)?e:u.createCallback(t,r,3),st(n,function(n,r,e){r=t(n,r,e),r>o&&(o=r,a=n)});return a}function Ht(n,t,r,e){var o=3>arguments.length;if(t=u.createCallback(t,e,4),Ce(n)){var a=-1,i=n.length;for(o&&i&&(r=n[++a]);++aarguments.length;return t=u.createCallback(t,e,4),pt(n,function(n,e,u){r=o?(o=false,n):t(r,n,e,u)}),r}function Qt(n){var t=-1,r=n?n.length:0,e=_r(typeof r=="number"?r:0); +return st(n,function(n){var r=_t(0,++t);e[t]=e[r],e[r]=n}),e}function Zt(n,t,r){var e;if(t=u.createCallback(t,r,3),Ce(n)){r=-1;for(var o=n.length;++rarguments.length)return kt(n,w,null,t);if(n)var r=n[A]?n[A][2]:n.length,e=Wt(arguments,2),r=r-e.length;return kt(n,w|k,r,t,e)}function tr(n,t,r){var e,u,o,a,i,l,f,c=0,s=false,p=true;if(!ar(n))throw new Sr;if(t=0=r||r>t?(u&&$r(u),r=f,u=l=f=_,r&&(c=Ne(),o=n.apply(i,e),l||u||(e=i=null))):l=Xr(h,r)},v=function(){l&&$r(l),u=l=f=_,(p||s!==t)&&(c=Ne(),o=n.apply(i,e),l||u||(e=i=null))};return function(){if(e=arguments,a=Ne(),i=this,f=p&&(l||!g),false===s)var r=g&&!l;else{u||g||(c=a);var y=s-(a-c),m=0>=y||y>s;m?(u&&(u=$r(u)),c=a,o=n.apply(i,e)):u||(u=Xr(v,y))}return m&&l?l=$r(l):l||t===s||(l=Xr(h,t)),r&&(m=true,o=n.apply(i,e)),!m||l||u||(e=i=null),o}}function rr(n,t,r){var e=arguments,u=0,o=e.length,a=typeof r; +if("number"!=a&&"string"!=a||!e[3]||e[3][r]!==t||(o=2),3t||null==n)return r;for(n=Ar(n);0--n?t.apply(this,arguments):void 0}},u.assign=rr,u.at=function(n,t){var r=arguments,e=-1,u=gt(r,true,false,1),o=u.length,a=typeof t;for("number"!=a&&"string"!=a||!r[2]||r[2][t]!==n||(o=1),ge.unindexedChars&&cr(n)&&(n=n.split("")),r=_r(o);++earguments.length?kt(t,w|x,null,n):kt(t,w|x|k,null,n,Wt(arguments,2))},u.chain=function(n){return n=new o(n),n.__chain__=true,n},u.compact=function(n){for(var t=-1,r=n?n.length:0,e=0,u=[];++t(g?r(g,f):a(l,f))){for(e=u,(g||l).push(f);--e;)if(g=o[e],0>(g?r(g,f):a(n[e],f)))continue n;p.push(f)}}return p},u.invert=function(n,t){for(var r=-1,e=ke(n),u=e.length,o={};++rarguments.length&&Ce(n))for(;++rr?te(0,e+r):re(r,e-1))+1);e--;)if(n[e]===t)return e; -return-1},u.mixin=vr,u.noConflict=function(){return n._=Tr,this},u.noop=yr,u.now=Ie,u.pad=function(n,t,r){n=null==n?"":Or(n),t=+t||0;var e=n.length;return en.length)return n;var o=r-e.length;if(1>o)return e;if(r=n.slice(0,o),null==u)return r+e;if(ir(u)){if(n.slice(o).search(u)){var a,i,l=n.slice(0,o);for(u.global||(u=kr(u.source,($.exec(u)||"")+"g")),u.lastIndex=0;a=u.exec(l);)i=a.index; -r=r.slice(0,null==i?o:i)}}else n.indexOf(u,o)!=o&&(u=r.lastIndexOf(u),-1n.indexOf(";")?n:n.replace(T,d))},u.uniqueId=function(n){var t=++S;return Or(null==n?"":n)+t},u.all=Bt,u.any=Jt,u.detect=Ut,u.findWhere=Ut,u.foldl=Yt,u.foldr=Gt,u.include=Dt,u.inject=Yt,vr(function(){var n={};return ht(u,function(t,r){u.prototype[r]||(n[r]=t)}),n}(),false),u.first=Rt,u.last=function(n,t,r){var e=n?n.length:0;if(typeof t!="number"&&null!=t){var o=e,a=0; -for(t=u.createCallback(t,r,3);o--&&t(n[o],o,n);)a++}else if(a=t,null==a||r)return n?n[e-1]:_;return a=e-a,Lt(n,0"']/g,P=/<%-([\s\S]+?)%>/g,F=/<%([\s\S]+?)%>/g,W=/<%=([\s\S]+?)%>/g,q=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,$=/\w*$/,D=/^\s*function[ \n\r\t]+\w/,B=/^0[xX]/,z=/[\xC0-\xFF]/g,U=/($^)/,K=/[.*+?^${}()|[\]\\]/g,M=/\bthis\b/,V=/['\n\r\t\u2028\u2029\\]/g,X=/[a-z0-9]+/g,Y=" \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",G="Array Boolean Date Error Function Math Number Object RegExp Set String _ clearTimeout document isFinite isNaN parseInt setTimeout TypeError window WinRTError".split(" "),H="constructor hasOwnProperty isPrototypeOf propertyIsEnumerable toLocaleString toString valueOf".split(" "),J="[object Arguments]",Q="[object Array]",Z="[object Boolean]",nt="[object Date]",tt="[object Error]",rt="[object Function]",et="[object Number]",ut="[object Object]",ot="[object RegExp]",at="[object String]",it={}; +}),e},u.has=function(n,t){return n?Ur.call(n,t):false},u.identity=vr,u.indexOf=Nt,u.isArguments=It,u.isArray=Ce,u.isBoolean=function(n){return true===n||false===n||n&&typeof n=="object"&&Wr.call(n)==Z||false},u.isDate=function(n){return n&&typeof n=="object"&&Wr.call(n)==nt||false},u.isElement=or,u.isEmpty=function(n){var t=true;if(!n)return t;var r=Wr.call(n),e=n.length;return r==Q||r==at||(ge.argsClass?r==J:It(n))||r==ut&&typeof e=="number"&&ar(n.splice)?!e:(ht(n,function(){return t=false}),t)},u.isEqual=function(n,t,r,e){if(r=typeof r=="function"&&z(r,e,2),!r){if(n===t)return 0!==n||1/n==1/t; +e=typeof n;var u=typeof t;if(n===n&&(null==n||null==t||"function"!=e&&"object"!=e&&"function"!=u&&"object"!=u))return false}return mt(n,t,r)},u.isFinite=function(n){return ne(n)&&!te(parseFloat(n))},u.isFunction=ar,u.isNaN=function(n){return lr(n)&&n!=+n},u.isNull=function(n){return null===n},u.isNumber=lr,u.isObject=ir,u.isPlainObject=je,u.isRegExp=fr,u.isString=cr,u.isUndefined=function(n){return typeof n=="undefined"},u.kebabCase=Ee,u.lastIndexOf=function(n,t,r){var e=n?n.length:0;for(typeof r=="number"&&(e=(0>r?ee(0,e+r):ue(r,e-1))+1);e--;)if(n[e]===t)return e; +return-1},u.mixin=mr,u.noConflict=function(){return n._=Pr,this},u.noop=dr,u.now=Ne,u.pad=function(n,t,r){n=null==n?"":Ar(n),t=+t||0;var e=n.length;return en.length)return n;var o=r-e.length;if(1>o)return e;if(r=n.slice(0,o),null==u)return r+e;if(fr(u)){if(n.slice(o).search(u)){var a,i,l=n.slice(0,o);for(u.global||(u=Er(u.source,($.exec(u)||"")+"g")),u.lastIndex=0;a=u.exec(l);)i=a.index; +r=r.slice(0,null==i?o:i)}}else n.indexOf(u,o)!=o&&(u=r.lastIndexOf(u),-1n.indexOf(";")?n:n.replace(T,d))},u.uniqueId=function(n){var t=++S;return Ar(null==n?"":n)+t},u.all=Ut,u.any=Zt,u.detect=Mt,u.findWhere=Mt,u.foldl=Ht,u.foldr=Jt,u.include=zt,u.inject=Ht,mr(function(){var n={};return ht(u,function(t,r){u.prototype[r]||(n[r]=t)}),n}(),false),u.first=Rt,u.last=Lt,u.sample=function(n,t,r){return n&&typeof n.length!="number"?n=sr(n):ge.unindexedChars&&cr(n)&&(n=n.split("")),null==t||r?n?n[_t(0,n.length-1)]:_:(n=Qt(n),n.length=ue(ee(0,t),n.length),n) +},u.take=Rt,u.takeRight=Lt,u.takeRightWhile=Lt,u.takeWhile=Rt,u.head=Rt,ht(u,function(n,t){var r="sample"!==t;u.prototype[t]||(u.prototype[t]=function(t,e){var u=this.__chain__,a=n(this.__wrapped__,t,e);return u||null!=t&&(!e||r&&typeof t=="function")?new o(a,u):a})}),u.VERSION=E,u.prototype.chain=function(){return this.__chain__=true,this},u.prototype.toString=function(){return Ar(this.__wrapped__)},u.prototype.value=Bt,u.prototype.valueOf=Bt,st(["join","pop","shift"],function(n){var t=Ir[n];u.prototype[n]=function(){var n=this.__chain__,r=t.apply(this.__wrapped__,arguments); +return n?new o(r,n):r}}),st(["push","reverse","sort","unshift"],function(n){var t=Ir[n];u.prototype[n]=function(){return t.apply(this.__wrapped__,arguments),this}}),st(["concat","splice"],function(n){var t=Ir[n];u.prototype[n]=function(){return new o(t.apply(this.__wrapped__,arguments),this.__chain__)}}),ge.spliceObjects||st(["pop","shift","splice"],function(n){var t=Ir[n],r="splice"==n;u.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 o(u,n):u +}}),u}var _,w=1,x=2,C=4,j=8,k=16,O=32,E="2.4.1",A="__lodash@"+E+"__",S=0,I=/\b__p\+='';/g,R=/\b(__p\+=)''\+/g,N=/(__e\(.*?\)|\b__t\))\+'';/g,T=/&(?:amp|lt|gt|quot|#39);/g,L=/[&<>"']/g,P=/<%-([\s\S]+?)%>/g,W=/<%([\s\S]+?)%>/g,F=/<%=([\s\S]+?)%>/g,q=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,$=/\w*$/,D=/^\s*function[ \n\r\t]+\w/,B=/^0[xX]/,z=/[\xC0-\xFF]/g,U=/($^)/,K=/[.*+?^${}()|[\]\\]/g,M=/\bthis\b/,V=/['\n\r\t\u2028\u2029\\]/g,X=/[a-z0-9]+/g,Y=" \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",G="Array Boolean Date Error Function Math Number Object RegExp Set String _ clearTimeout document isFinite isNaN parseInt setTimeout TypeError window WinRTError".split(" "),H="constructor hasOwnProperty isPrototypeOf propertyIsEnumerable toLocaleString toString valueOf".split(" "),J="[object Arguments]",Q="[object Array]",Z="[object Boolean]",nt="[object Date]",tt="[object Error]",rt="[object Function]",et="[object Number]",ut="[object Object]",ot="[object RegExp]",at="[object String]",it={}; it[rt]=false,it[J]=it[Q]=it[Z]=it[nt]=it[et]=it[ut]=it[ot]=it[at]=true;var lt={leading:false,maxWait:0,trailing:false},ft={configurable:false,enumerable:false,value:null,writable:false},ct={"&":"&","<":"<",">":">",'"':""","'":"'"},st={"&":"&","<":"<",">":">",""":'"',"'":"'"},pt={\u00c0:"A",\u00c1:"A",\u00c2:"A",\u00c3:"A",\u00c4:"A",\u00c5:"A",\u00e0:"a",\u00e1:"a",\u00e2:"a",\u00e3:"a",\u00e4:"a",\u00e5:"a",\u00c7:"C",\u00e7:"c",\u00d0:"D",\u00f0:"d",\u00c8:"E",\u00c9:"E",\u00ca:"E",\u00cb:"E",\u00e8:"e",\u00e9:"e",\u00ea:"e",\u00eb:"e",\u00cc:"I",\u00cd:"I",\u00ce:"I",\u00cf:"I",\u00ec:"i",\u00ed:"i",\u00ee:"i",\u00ef:"i",\u00d1:"N",\u00f1:"n",\u00d2:"O",\u00d3:"O",\u00d4:"O",\u00d5:"O",\u00d6:"O",\u00d8:"O",\u00f2:"o",\u00f3:"o",\u00f4:"o",\u00f5:"o",\u00f6:"o",\u00f8:"o",\u00d9:"U",\u00da:"U",\u00db:"U",\u00dc:"U",\u00f9:"u",\u00fa:"u",\u00fb:"u",\u00fc:"u",\u00dd:"Y",\u00fd:"y",\u00ff:"y",\u00c6:"AE",\u00e6:"ae",\u00de:"Th",\u00fe:"th",\u00df:"ss","\xd7":"","\xf7":""},gt={"function":true,object:true},ht={"\\":"\\","'":"'","\n":"n","\r":"r","\t":"t","\u2028":"u2028","\u2029":"u2029"},vt=gt[typeof window]&&window||this,yt=gt[typeof exports]&&exports&&!exports.nodeType&&exports,gt=gt[typeof module]&&module&&!module.nodeType&&module,mt=yt&>&&typeof global=="object"&&global; !mt||mt.global!==mt&&mt.window!==mt&&mt.self!==mt||(vt=mt);var mt=gt&>.exports===yt&&yt,dt=b();typeof define=="function"&&typeof define.amd=="object"&&define.amd?(vt._=dt, define(function(){return dt})):yt&>?mt?(gt.exports=dt)._=dt:yt._=dt:vt._=dt}).call(this); \ No newline at end of file diff --git a/dist/lodash.js b/dist/lodash.js index 5510a56a7..72bdc0b91 100644 --- a/dist/lodash.js +++ b/dist/lodash.js @@ -2033,6 +2033,9 @@ * @returns {Array} Returns the slice of `array`. * @example * + * _.drop([1, 2, 3], 1); + * // => [2, 3] + * * _.drop([1, 2, 3], 2); * // => [3] * @@ -2045,9 +2048,79 @@ var drop = rest; /** - * Creates an array with elements dropped from the beginning of `array` as - * long as the predicate returns truthy. The predicate is bound to `thisArg` - * and invoked with three arguments; (value, index, array). + * Creates an array with `n` elements dropped from the end of `array`. + * + * @static + * @memberOf _ + * @type Function + * @category Arrays + * @param {Array} array The array to query. + * @param {number} [n=1] The number of elements to drop. + * @returns {Array} Returns the slice of `array`. + * @example + * + * _.dropRight([1, 2, 3], 1); + * // => [1, 2] + * + * _.dropRight([1, 2, 3], 2); + * // => [1] + * + * _.dropRight([1, 2, 3], 5); + * // => [] + * + * _.dropRight([1, 2, 3], 0); + * // => [1, 2, 3] + */ + var dropRight = initial; + + /** + * Creates an array of elements excluding those dropped from the end of `array`. + * Elements will be dropped until the predicate returns falsey. The predicate + * is bound to `thisArg`nand invoked with three arguments; (value, index, array). + * + * If a property name is provided for `predicate` the created "_.pluck" style + * callback will return the property value of the given element. + * + * If an object is provided for `predicate` the created "_.where" style callback + * will return `true` for elements that have the properties of the given object, + * else `false`. + * + * @static + * @memberOf _ + * @type Function + * @category Arrays + * @param {Array} array The array to query. + * @param {Function|Object|string} [predicate=identity] The function called + * per element. + * @returns {Array} Returns the slice of `array`. + * @example + * + * _.dropRightWhile([1, 2, 3], function(num) { + * return num > 1; + * }); + * // => [1] + * + * var characters = [ + * { 'name': 'barney', 'employer': 'slate' }, + * { 'name': 'fred', 'employer': 'slate', 'blocked': true }, + * { 'name': 'pebbles', 'employer': 'na', 'blocked': true } + * ]; + * + * // using "_.pluck" callback shorthand + * _.pluck(_.dropRightWhile(characters, 'blocked'), 'name'); + * // => ['barney'] + * + * // using "_.where" callback shorthand + * _.pluck(_.dropRightWhile(characters, { 'employer': 'na' }), 'name'); + * // => ['barney', 'fred'] + */ + var dropRightWhile = initial; + + /** + * Creates an array of elements excluding those dropped from the beginning + * of `array`. Elements will be dropped until the predicate returns falsey. + * The predicate is bound to `thisArg` and invoked with three arguments; + * (value, index, array). * * If a property name is provided for `predicate` the created "_.pluck" style * callback will return the property value of the given element. @@ -2777,21 +2850,93 @@ * @returns {Array} Returns the slice of `array`. * @example * + * _.take([1, 2, 3], 1); + * // => [2] + * * _.take([1, 2, 3], 2); * // => [1, 2] * * _.take([1, 2, 3], 5); * // => [1, 2, 3] * - * _.take([1, 2, 3], -1); + * _.take([1, 2, 3], 0); * // => [] */ var take = first; /** - * Creates an array of elements from the beginning of `array` while the - * predicate returns truthy. The predicate is bound to `thisArg` and invoked - * with three arguments; (value, index, array). + * Creates an array of the last `n` elements of `array`. + * + * @static + * @memberOf _ + * @type Function + * @category Arrays + * @param {Array} array The array to query. + * @param {number} [n=1] The number of elements to take. + * @returns {Array} Returns the slice of `array`. + * @example + * + * _.takeRight([1, 2, 3], 1); + * // => [3] + * + * _.takeRight([1, 2, 3], 2); + * // => [2, 3] + * + * _.takeRight([1, 2, 3], 5); + * // => [1, 2, 3] + * + * _.takeRight([1, 2, 3], 0); + * // => [] + */ + var takeRight = last; + + /** + * Creates an array of elements from the end of `array`. Elements will be + * taken until the predicate returns falsey. The predicate is bound to `thisArg` + * and invoked with three arguments; (value, index, array). + * + * If a property name is provided for `predicate` the created "_.pluck" style + * callback will return the property value of the given element. + * + * If an object is provided for `predicate` the created "_.where" style callback + * will return `true` for elements that have the properties of the given object, + * else `false`. + * + * @static + * @memberOf _ + * @type Function + * @category Arrays + * @param {Array} array The array to query. + * @param {Function|Object|string} [predicate=identity] The function called + * per element. + * @returns {Array} Returns the slice of `array`. + * @example + * + * _.takeRightWhile([1, 2, 3], function(num) { + * return num > 1; + * }); + * // => [2, 3] + * + * var characters = [ + * { 'name': 'barney', 'employer': 'slate' }, + * { 'name': 'fred', 'employer': 'slate', 'blocked': true }, + * { 'name': 'pebbles', 'employer': 'na', 'blocked': true } + * ]; + * + * // using "_.pluck" callback shorthand + * _.pluck(_.takeRightWhile(characters, 'blocked'), 'name'); + * // => ['fred', 'pebbles'] + * + * // using "_.where" callback shorthand + * _.pluck(_.takeRightWhile(characters, { 'employer': 'na' }), 'name'); + * // => ['pebbles'] + */ + var takeRightWhile = last; + + /** + * Creates an array of elements from the beginning of `array`. Elements will + * be taken until the predicate returns falsey. The predicate is bound to + * `thisArg` and invoked with three arguments; (value, index, array). * * If a property name is provided for `predicate` the created "_.pluck" style * callback will return the property value of the given element. @@ -7661,6 +7806,8 @@ lodash.delay = delay; lodash.difference = difference; lodash.drop = drop; + lodash.dropRight = dropRight; + lodash.dropRightWhile = dropRightWhile; lodash.dropWhile = dropWhile; lodash.filter = filter; lodash.flatten = flatten; @@ -7827,6 +7974,8 @@ lodash.last = last; lodash.sample = sample; lodash.take = first; + lodash.takeRight = last; + lodash.takeRightWhile = last; lodash.takeWhile = first; // add aliases diff --git a/dist/lodash.min.js b/dist/lodash.min.js index 5f7c4ffac..ad163b5e3 100644 --- a/dist/lodash.min.js +++ b/dist/lodash.min.js @@ -5,60 +5,60 @@ */ ;(function(){function n(n,t){if(n!==t){if(n>t||typeof n=="undefined")return 1;if(ne||13e||8202r||13r||8202i(e,f)&&l.push(f);return l}function ct(n,t){var r=-1,e=n?n.length:0;if(typeof e=="number")for(;++ra(p,h)&&((u||l)&&p.push(h),c.push(s))}return c}function wt(n,t,r){for(var e=t.length,u=-1,o=Jr(r.length-e,0),i=-1,a=n.length,f=yr(o+a);++ir&&(r=0),c&&(i=[]),p&&(a=[]),s=[n,t,r,e,u,o,i,a],t==_||t==(_|k)?y(s):ft(s)) -}function Ct(){var n=(n=l.indexOf)===Rt?t:n;return n}function Ot(n){return typeof n=="function"&&Sr.test($r.call(n))}function At(n){var t,r;return n&&Nr.call(n)==tt&&(Lr.call(n,"constructor")||(t=n.constructor,!rr(t)||t instanceof t))?(o(n,function(n,t){r=t}),typeof r=="undefined"||Lr.call(n,r)):false}function Et(n){return n&&typeof n=="object"&&typeof n.length=="number"&&Nr.call(n)==G||false}function It(n,t,r){if(typeof t!="number"&&null!=t){var e=-1,u=n?n.length:0,o=0;for(t=l.createCallback(t,r,3);++ee?Jr(0,u+e):e||0;else if(e)return e=Tt(n,r),u&&n[e]===r?e:-1;return t(n,r,e)}function Nt(n,t,r){if(typeof t!="number"&&null!=t){var e=-1,u=n?n.length:0,o=0;for(t=l.createCallback(t,r,3);++et?t=Jr(u+t,0):t>u&&(t=u),typeof r=="undefined"?r=u:0>r?r=Jr(u+r,0):r>u&&(r=u),u=r-t||0,r=yr(u);++e>>1,r(n[e])r?0:r);++t=e)return false;if(typeof n=="string"||!ve(n)&&ir(n))return Mr?Mr.call(n,t,r):-1r?Jr(0,e+r):r)||0,-1o&&(o=a)}else t=null==t&&ir(n)?e:l.createCallback(t,r,3),ct(n,function(n,r,e){r=t(n,r,e),r>u&&(u=r,o=n)});return o}function Vt(n,t,r,e){var u=3>arguments.length;t=l.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=l.createCallback(t,e,4),pt(n,function(n,e,o){r=u?(u=false,n):t(r,n,e,o)}),r}function Yt(n){var t=-1,r=n?n.length:0,e=yr(typeof r=="number"?r:0);return ct(n,function(n){var r=bt(0,++t);e[t]=e[r],e[r]=n}),e}function Gt(n,t,r){var e;t=l.createCallback(t,r,3),r=-1;var u=n?n.length:0;if(typeof u=="number"){for(;++rarguments.length)return kt(n,_,null,t); -if(n)var r=n[A]?n[A][2]:n.length,e=St(arguments,2),r=r-e.length;return kt(n,_|k,r,t,e)}function Jt(n,t,r){function e(){c&&Fr(c),i=c=p=b,(g||h!==t)&&(s=ke(),a=n.apply(l,o),c||i||(o=l=null))}function u(){var r=t-(ke()-f);0>=r||r>t?(i&&Fr(i),r=p,i=c=p=b,r&&(s=ke(),a=n.apply(l,o),c||i||(o=l=null))):c=zr(u,r)}var o,i,a,f,l,c,p,s=0,h=false,g=true;if(!rr(n))throw new Cr;if(t=0=y||y>h;m?(i&&(i=Fr(i)),s=f,a=n.apply(l,o)):i||(i=zr(e,y))}return m&&c?c=Fr(c):c||t===h||(c=zr(u,t)),r&&(m=true,a=n.apply(l,o)),!m||c||i||(o=l=null),a}}function Qt(n,t,r){var e=arguments,u=0,o=e.length,i=typeof r;if("number"!=i&&"string"!=i||!e[3]||e[3][r]!==t||(o=2),3t||null==n)return r;for(n=kr(n);0--n?t.apply(this,arguments):void 0 -}},l.assign=Qt,l.at=function(n,t){var r=arguments,e=-1,u=ht(r,true,false,1),o=u.length,i=typeof t;for("number"!=i&&"string"!=i||!r[2]||r[2][t]!==n||(o=1),r=yr(o);++earguments.length?kt(t,_|w,null,n):kt(t,_|w|k,null,n,St(arguments,2))},l.chain=function(n){return n=new v(n),n.__chain__=true,n -},l.compact=function(n){for(var t=-1,r=n?n.length:0,e=0,u=[];++t(h?r(h,l):i(f,l))){for(e=u,(h||f).push(l);--e;)if(h=o[e],0>(h?r(h,l):i(n[e],l)))continue n;s.push(l) -}}return s},l.invert=function(n,t){for(var r=-1,e=me(n),u=e.length,o={};++rarguments.length&&typeof u=="number")for(;++re||13e||8202r||13r||8202i(e,f)&&l.push(f);return l}function ct(n,t){var r=-1,e=n?n.length:0;if(typeof e=="number")for(;++ra(p,h)&&((u||l)&&p.push(h),c.push(s))}return c}function wt(n,t,r){for(var e=t.length,u=-1,o=Zr(r.length-e,0),i=-1,a=n.length,f=dr(o+a);++ir&&(r=0),c&&(i=[]),p&&(a=[]),s=[n,t,r,e,u,o,i,a],t==_||t==(_|j)?y(s):ft(s)) +}function Ct(){var n=(n=l.indexOf)===Rt?t:n;return n}function Ot(n){return typeof n=="function"&&Wr.test(Lr.call(n))}function At(n){var t,r;return n&&Tr.call(n)==tt&&(qr.call(n,"constructor")||(t=n.constructor,!ur(t)||t instanceof t))?(o(n,function(n,t){r=t}),typeof r=="undefined"||qr.call(n,r)):false}function Et(n){return n&&typeof n=="object"&&typeof n.length=="number"&&Tr.call(n)==G||false}function It(n,t,r){if(typeof t!="number"&&null!=t){var e=-1,u=n?n.length:0,o=0;for(t=l.createCallback(t,r,3);++ee?Zr(0,u+e):e||0;else if(e)return e=Ft(n,r),u&&n[e]===r?e:-1;return t(n,r,e)}function Nt(n,t,r){var e=n?n.length:0;if(typeof t!="number"&&null!=t){var u=e,o=0;for(t=l.createCallback(t,r,3);u--&&t(n[u],u,n);)o++}else o=null==t||r?1:t;return o=e-o,Wt(n,0,0t?t=Zr(u+t,0):t>u&&(t=u),typeof r=="undefined"?r=u:0>r?r=Zr(u+r,0):r>u&&(r=u),u=r-t||0,r=dr(u);++e>>1,r(n[e])r?0:r);++t=e)return false;if(typeof n=="string"||!me(n)&&fr(n))return Xr?Xr.call(n,t,r):-1r?Zr(0,e+r):r)||0,-1o&&(o=a) +}else t=null==t&&fr(n)?e:l.createCallback(t,r,3),ct(n,function(n,r,e){r=t(n,r,e),r>u&&(u=r,o=n)});return o}function Yt(n,t,r,e){var u=3>arguments.length;t=l.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=l.createCallback(t,e,4),pt(n,function(n,e,o){r=u?(u=false,n):t(r,n,e,o)}),r}function Ht(n){var t=-1,r=n?n.length:0,e=dr(typeof r=="number"?r:0); +return ct(n,function(n){var r=bt(0,++t);e[t]=e[r],e[r]=n}),e}function Jt(n,t,r){var e;t=l.createCallback(t,r,3),r=-1;var u=n?n.length:0;if(typeof u=="number"){for(;++rarguments.length)return jt(n,_,null,t);if(n)var r=n[A]?n[A][2]:n.length,e=Wt(arguments,2),r=r-e.length;return jt(n,_|j,r,t,e)}function Zt(n,t,r){function e(){c&&$r(c),i=c=p=b,(g||h!==t)&&(s=Oe(),a=n.apply(l,o),c||i||(o=l=null)) +}function u(){var r=t-(Oe()-f);0>=r||r>t?(i&&$r(i),r=p,i=c=p=b,r&&(s=Oe(),a=n.apply(l,o),c||i||(o=l=null))):c=Pr(u,r)}var o,i,a,f,l,c,p,s=0,h=false,g=true;if(!ur(n))throw new Ar;if(t=0=y||y>h;m?(i&&(i=$r(i)),s=f,a=n.apply(l,o)):i||(i=Pr(e,y))}return m&&c?c=$r(c):c||t===h||(c=Pr(u,t)),r&&(m=true,a=n.apply(l,o)),!m||c||i||(o=l=null),a +}}function nr(n,t,r){var e=arguments,u=0,o=e.length,i=typeof r;if("number"!=i&&"string"!=i||!e[3]||e[3][r]!==t||(o=2),3t||null==n)return r;for(n=Or(n);0--n?t.apply(this,arguments):void 0 +}},l.assign=nr,l.at=function(n,t){var r=arguments,e=-1,u=ht(r,true,false,1),o=u.length,i=typeof t;for("number"!=i&&"string"!=i||!r[2]||r[2][t]!==n||(o=1),r=dr(o);++earguments.length?jt(t,_|w,null,n):jt(t,_|w|j,null,n,Wt(arguments,2))},l.chain=function(n){return n=new v(n),n.__chain__=true,n +},l.compact=function(n){for(var t=-1,r=n?n.length:0,e=0,u=[];++t(h?r(h,l):i(f,l))){for(e=u,(h||f).push(l);--e;)if(h=o[e],0>(h?r(h,l):i(n[e],l)))continue n;s.push(l)}}return s},l.invert=function(n,t){for(var r=-1,e=be(n),u=e.length,o={};++rarguments.length&&typeof u=="number")for(;++rr?Jr(0,e+r):Qr(r,e-1))+1);e--;)if(n[e]===t)return e; -return-1},l.mixin=hr,l.noConflict=function(){return n._=Rr,this},l.noop=gr,l.now=ke,l.pad=function(n,t,r){n=null==n?"":kr(n),t=+t||0;var e=n.length;return en.length)return n;var o=r-e.length;if(1>o)return e;if(r=n.slice(0,o),null==u)return r+e;if(or(u)){if(n.slice(o).search(u)){var i,a,f=n.slice(0,o);for(u.global||(u=jr(u.source,(L.exec(u)||"")+"g")),u.lastIndex=0;i=u.exec(f);)a=i.index; -r=r.slice(0,null==a?o:a)}}else n.indexOf(u,o)!=o&&(u=r.lastIndexOf(u),-1n.indexOf(";")?n:n.replace(S,m))},l.uniqueId=function(n){var t=++E;return kr(null==n?"":n)+t},l.all=Bt,l.any=Gt,l.detect=zt,l.findWhere=zt,l.foldl=Vt,l.foldr=Xt,l.include=Lt,l.inject=Vt,hr(function(){var n={};return gt(l,function(t,r){l.prototype[r]||(n[r]=t)}),n}(),false),l.first=It,l.last=function(n,t,r){var e=n?n.length:0;if(typeof t!="number"&&null!=t){var u=e,o=0; -for(t=l.createCallback(t,r,3);u--&&t(n[u],u,n);)o++}else if(o=t,null==o||r)return n?n[e-1]:b;return o=e-o,St(n,0"']/g,F=/<%-([\s\S]+?)%>/g,W=/<%([\s\S]+?)%>/g,$=/<%=([\s\S]+?)%>/g,D=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,L=/\w*$/,B=/^\s*function[ \n\r\t]+\w/,q=/^0[xX]/,z=/[\xC0-\xFF]/g,U=/($^)/,P=/[.*+?^${}()|[\]\\]/g,K=/\bthis\b/,M=/['\n\r\t\u2028\u2029\\]/g,V=/[a-z0-9]+/g,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",Y="Array Boolean Date Function Math Number Object RegExp Set String _ clearTimeout document isFinite isNaN parseInt setTimeout TypeError window WinRTError".split(" "),G="[object Arguments]",H="[object Array]",J="[object Boolean]",Q="[object Date]",Z="[object Function]",nt="[object Number]",tt="[object Object]",rt="[object RegExp]",et="[object String]",ut={}; +}),e},l.has=function(n,t){return n?qr.call(n,t):false},l.identity=hr,l.indexOf=Rt,l.isArguments=Et,l.isArray=me,l.isBoolean=function(n){return true===n||false===n||n&&typeof n=="object"&&Tr.call(n)==J||false},l.isDate=function(n){return n&&typeof n=="object"&&Tr.call(n)==Q||false},l.isElement=er,l.isEmpty=function(n){var t=true;if(!n)return t;var r=Tr.call(n),e=n.length;return r==H||r==et||r==G||r==tt&&typeof e=="number"&&ur(n.splice)?!e:(gt(n,function(){return t=false}),t)},l.isEqual=function(n,t,r,e){if(r=typeof r=="function"&&at(r,e,2),!r){if(n===t)return 0!==n||1/n==1/t; +e=typeof n;var u=typeof t;if(n===n&&(null==n||null==t||"function"!=e&&"object"!=e&&"function"!=u&&"object"!=u))return false}return mt(n,t,r)},l.isFinite=function(n){return Hr(n)&&!Jr(parseFloat(n))},l.isFunction=ur,l.isNaN=function(n){return ir(n)&&n!=+n},l.isNull=function(n){return null===n},l.isNumber=ir,l.isObject=or,l.isPlainObject=de,l.isRegExp=ar,l.isString=fr,l.isUndefined=function(n){return typeof n=="undefined"},l.kebabCase=we,l.lastIndexOf=function(n,t,r){var e=n?n.length:0;for(typeof r=="number"&&(e=(0>r?Zr(0,e+r):ne(r,e-1))+1);e--;)if(n[e]===t)return e; +return-1},l.mixin=vr,l.noConflict=function(){return n._=Sr,this},l.noop=yr,l.now=Oe,l.pad=function(n,t,r){n=null==n?"":Or(n),t=+t||0;var e=n.length;return en.length)return n;var o=r-e.length;if(1>o)return e;if(r=n.slice(0,o),null==u)return r+e;if(ar(u)){if(n.slice(o).search(u)){var i,a,f=n.slice(0,o);for(u.global||(u=Cr(u.source,(L.exec(u)||"")+"g")),u.lastIndex=0;i=u.exec(f);)a=i.index; +r=r.slice(0,null==a?o:a)}}else n.indexOf(u,o)!=o&&(u=r.lastIndexOf(u),-1n.indexOf(";")?n:n.replace(S,m))},l.uniqueId=function(n){var t=++E;return Or(null==n?"":n)+t},l.all=zt,l.any=Jt,l.detect=Pt,l.findWhere=Pt,l.foldl=Yt,l.foldr=Gt,l.include=qt,l.inject=Yt,vr(function(){var n={};return gt(l,function(t,r){l.prototype[r]||(n[r]=t)}),n}(),false),l.first=It,l.last=St,l.sample=function(n,t,r){return n&&typeof n.length!="number"&&(n=lr(n)),null==t||r?n?n[bt(0,n.length-1)]:b:(n=Ht(n),n.length=ne(Zr(0,t),n.length),n) +},l.take=It,l.takeRight=St,l.takeRightWhile=St,l.takeWhile=It,l.head=It,gt(l,function(n,t){var r="sample"!==t;l.prototype[t]||(l.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 v(o,u):o})}),l.VERSION=O,l.prototype.chain=function(){return this.__chain__=true,this},l.prototype.toString=function(){return Or(this.__wrapped__)},l.prototype.value=Bt,l.prototype.valueOf=Bt,ct(["join","pop","shift"],function(n){var t=Er[n];l.prototype[n]=function(){var n=this.__chain__,r=t.apply(this.__wrapped__,arguments); +return n?new v(r,n):r}}),ct(["push","reverse","sort","unshift"],function(n){var t=Er[n];l.prototype[n]=function(){return t.apply(this.__wrapped__,arguments),this}}),ct(["concat","splice"],function(n){var t=Er[n];l.prototype[n]=function(){return new v(t.apply(this.__wrapped__,arguments),this.__chain__)}}),l}var b,_=1,w=2,x=4,k=8,j=16,C=32,O="2.4.1",A="__lodash@"+O+"__",E=0,I=/\b__p\+='';/g,R=/\b(__p\+=)''\+/g,N=/(__e\(.*?\)|\b__t\))\+'';/g,S=/&(?:amp|lt|gt|quot|#39);/g,T=/[&<>"']/g,W=/<%-([\s\S]+?)%>/g,F=/<%([\s\S]+?)%>/g,$=/<%=([\s\S]+?)%>/g,D=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,L=/\w*$/,B=/^\s*function[ \n\r\t]+\w/,q=/^0[xX]/,z=/[\xC0-\xFF]/g,U=/($^)/,P=/[.*+?^${}()|[\]\\]/g,K=/\bthis\b/,M=/['\n\r\t\u2028\u2029\\]/g,V=/[a-z0-9]+/g,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",Y="Array Boolean Date Function Math Number Object RegExp Set String _ clearTimeout document isFinite isNaN parseInt setTimeout TypeError window WinRTError".split(" "),G="[object Arguments]",H="[object Array]",J="[object Boolean]",Q="[object Date]",Z="[object Function]",nt="[object Number]",tt="[object Object]",rt="[object RegExp]",et="[object String]",ut={}; ut[Z]=false,ut[G]=ut[H]=ut[J]=ut[Q]=ut[nt]=ut[tt]=ut[rt]=ut[et]=true;var ot={leading:false,maxWait:0,trailing:false},it={configurable:false,enumerable:false,value:null,writable:false},at={"&":"&","<":"<",">":">",'"':""","'":"'"},ft={"&":"&","<":"<",">":">",""":'"',"'":"'"},lt={\u00c0:"A",\u00c1:"A",\u00c2:"A",\u00c3:"A",\u00c4:"A",\u00c5:"A",\u00e0:"a",\u00e1:"a",\u00e2:"a",\u00e3:"a",\u00e4:"a",\u00e5:"a",\u00c7:"C",\u00e7:"c",\u00d0:"D",\u00f0:"d",\u00c8:"E",\u00c9:"E",\u00ca:"E",\u00cb:"E",\u00e8:"e",\u00e9:"e",\u00ea:"e",\u00eb:"e",\u00cc:"I",\u00cd:"I",\u00ce:"I",\u00cf:"I",\u00ec:"i",\u00ed:"i",\u00ee:"i",\u00ef:"i",\u00d1:"N",\u00f1:"n",\u00d2:"O",\u00d3:"O",\u00d4:"O",\u00d5:"O",\u00d6:"O",\u00d8:"O",\u00f2:"o",\u00f3:"o",\u00f4:"o",\u00f5:"o",\u00f6:"o",\u00f8:"o",\u00d9:"U",\u00da:"U",\u00db:"U",\u00dc:"U",\u00f9:"u",\u00fa:"u",\u00fb:"u",\u00fc:"u",\u00dd:"Y",\u00fd:"y",\u00ff:"y",\u00c6:"AE",\u00e6:"ae",\u00de:"Th",\u00fe:"th",\u00df:"ss","\xd7":"","\xf7":""},ct={"function":true,object:true},pt={"\\":"\\","'":"'","\n":"n","\r":"r","\t":"t","\u2028":"u2028","\u2029":"u2029"},st=ct[typeof window]&&window||this,ht=ct[typeof exports]&&exports&&!exports.nodeType&&exports,ct=ct[typeof module]&&module&&!module.nodeType&&module,gt=ht&&ct&&typeof global=="object"&&global; !gt||gt.global!==gt&>.window!==gt&>.self!==gt||(st=gt);var gt=ct&&ct.exports===ht&&ht,vt=d();typeof define=="function"&&typeof define.amd=="object"&&define.amd?(st._=vt, define(function(){return vt})):ht&&ct?gt?(ct.exports=vt)._=vt:ht._=vt:st._=vt}).call(this); \ No newline at end of file diff --git a/dist/lodash.underscore.js b/dist/lodash.underscore.js index 4ef0a5d46..98df5d50d 100644 --- a/dist/lodash.underscore.js +++ b/dist/lodash.underscore.js @@ -1151,6 +1151,9 @@ * @returns {Array} Returns the slice of `array`. * @example * + * _.drop([1, 2, 3], 1); + * // => [2, 3] + * * _.drop([1, 2, 3], 2); * // => [3] * @@ -1595,13 +1598,16 @@ * @returns {Array} Returns the slice of `array`. * @example * + * _.take([1, 2, 3], 1); + * // => [2] + * * _.take([1, 2, 3], 2); * // => [1, 2] * * _.take([1, 2, 3], 5); * // => [1, 2, 3] * - * _.take([1, 2, 3], -1); + * _.take([1, 2, 3], 0); * // => [] */ var take = first; diff --git a/lodash.js b/lodash.js index dbd9f135d..5118ac303 100644 --- a/lodash.js +++ b/lodash.js @@ -2331,6 +2331,9 @@ * @returns {Array} Returns the slice of `array`. * @example * + * _.drop([1, 2, 3], 1); + * // => [2, 3] + * * _.drop([1, 2, 3], 2); * // => [3] * @@ -2343,9 +2346,79 @@ var drop = rest; /** - * Creates an array with elements dropped from the beginning of `array` as - * long as the predicate returns truthy. The predicate is bound to `thisArg` - * and invoked with three arguments; (value, index, array). + * Creates an array with `n` elements dropped from the end of `array`. + * + * @static + * @memberOf _ + * @type Function + * @category Arrays + * @param {Array} array The array to query. + * @param {number} [n=1] The number of elements to drop. + * @returns {Array} Returns the slice of `array`. + * @example + * + * _.dropRight([1, 2, 3], 1); + * // => [1, 2] + * + * _.dropRight([1, 2, 3], 2); + * // => [1] + * + * _.dropRight([1, 2, 3], 5); + * // => [] + * + * _.dropRight([1, 2, 3], 0); + * // => [1, 2, 3] + */ + var dropRight = initial; + + /** + * Creates an array of elements excluding those dropped from the end of `array`. + * Elements will be dropped until the predicate returns falsey. The predicate + * is bound to `thisArg`nand invoked with three arguments; (value, index, array). + * + * If a property name is provided for `predicate` the created "_.pluck" style + * callback will return the property value of the given element. + * + * If an object is provided for `predicate` the created "_.where" style callback + * will return `true` for elements that have the properties of the given object, + * else `false`. + * + * @static + * @memberOf _ + * @type Function + * @category Arrays + * @param {Array} array The array to query. + * @param {Function|Object|string} [predicate=identity] The function called + * per element. + * @returns {Array} Returns the slice of `array`. + * @example + * + * _.dropRightWhile([1, 2, 3], function(num) { + * return num > 1; + * }); + * // => [1] + * + * var characters = [ + * { 'name': 'barney', 'employer': 'slate' }, + * { 'name': 'fred', 'employer': 'slate', 'blocked': true }, + * { 'name': 'pebbles', 'employer': 'na', 'blocked': true } + * ]; + * + * // using "_.pluck" callback shorthand + * _.pluck(_.dropRightWhile(characters, 'blocked'), 'name'); + * // => ['barney'] + * + * // using "_.where" callback shorthand + * _.pluck(_.dropRightWhile(characters, { 'employer': 'na' }), 'name'); + * // => ['barney', 'fred'] + */ + var dropRightWhile = initial; + + /** + * Creates an array of elements excluding those dropped from the beginning + * of `array`. Elements will be dropped until the predicate returns falsey. + * The predicate is bound to `thisArg` and invoked with three arguments; + * (value, index, array). * * If a property name is provided for `predicate` the created "_.pluck" style * callback will return the property value of the given element. @@ -3075,21 +3148,93 @@ * @returns {Array} Returns the slice of `array`. * @example * + * _.take([1, 2, 3], 1); + * // => [2] + * * _.take([1, 2, 3], 2); * // => [1, 2] * * _.take([1, 2, 3], 5); * // => [1, 2, 3] * - * _.take([1, 2, 3], -1); + * _.take([1, 2, 3], 0); * // => [] */ var take = first; /** - * Creates an array of elements from the beginning of `array` while the - * predicate returns truthy. The predicate is bound to `thisArg` and invoked - * with three arguments; (value, index, array). + * Creates an array of the last `n` elements of `array`. + * + * @static + * @memberOf _ + * @type Function + * @category Arrays + * @param {Array} array The array to query. + * @param {number} [n=1] The number of elements to take. + * @returns {Array} Returns the slice of `array`. + * @example + * + * _.takeRight([1, 2, 3], 1); + * // => [3] + * + * _.takeRight([1, 2, 3], 2); + * // => [2, 3] + * + * _.takeRight([1, 2, 3], 5); + * // => [1, 2, 3] + * + * _.takeRight([1, 2, 3], 0); + * // => [] + */ + var takeRight = last; + + /** + * Creates an array of elements from the end of `array`. Elements will be + * taken until the predicate returns falsey. The predicate is bound to `thisArg` + * and invoked with three arguments; (value, index, array). + * + * If a property name is provided for `predicate` the created "_.pluck" style + * callback will return the property value of the given element. + * + * If an object is provided for `predicate` the created "_.where" style callback + * will return `true` for elements that have the properties of the given object, + * else `false`. + * + * @static + * @memberOf _ + * @type Function + * @category Arrays + * @param {Array} array The array to query. + * @param {Function|Object|string} [predicate=identity] The function called + * per element. + * @returns {Array} Returns the slice of `array`. + * @example + * + * _.takeRightWhile([1, 2, 3], function(num) { + * return num > 1; + * }); + * // => [2, 3] + * + * var characters = [ + * { 'name': 'barney', 'employer': 'slate' }, + * { 'name': 'fred', 'employer': 'slate', 'blocked': true }, + * { 'name': 'pebbles', 'employer': 'na', 'blocked': true } + * ]; + * + * // using "_.pluck" callback shorthand + * _.pluck(_.takeRightWhile(characters, 'blocked'), 'name'); + * // => ['fred', 'pebbles'] + * + * // using "_.where" callback shorthand + * _.pluck(_.takeRightWhile(characters, { 'employer': 'na' }), 'name'); + * // => ['pebbles'] + */ + var takeRightWhile = last; + + /** + * Creates an array of elements from the beginning of `array`. Elements will + * be taken until the predicate returns falsey. The predicate is bound to + * `thisArg` and invoked with three arguments; (value, index, array). * * If a property name is provided for `predicate` the created "_.pluck" style * callback will return the property value of the given element. @@ -7975,6 +8120,8 @@ lodash.delay = delay; lodash.difference = difference; lodash.drop = drop; + lodash.dropRight = dropRight; + lodash.dropRightWhile = dropRightWhile; lodash.dropWhile = dropWhile; lodash.filter = filter; lodash.flatten = flatten; @@ -8141,6 +8288,8 @@ lodash.last = last; lodash.sample = sample; lodash.take = first; + lodash.takeRight = last; + lodash.takeRightWhile = last; lodash.takeWhile = first; // add aliases diff --git a/test/test.js b/test/test.js index 4d9f4cee9..477ae8173 100644 --- a/test/test.js +++ b/test/test.js @@ -9274,7 +9274,7 @@ var acceptFalsey = _.difference(allMethods, rejectFalsey); - test('should accept falsey arguments', 178, function() { + test('should accept falsey arguments', 182, function() { var emptyArrays = _.map(falsey, function() { return []; }), isExposed = '_' in root, oldDash = root._;