diff --git a/README.md b/README.md index 60f099ae64..3775a4111c 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Lo-Dash v0.8.1 +# Lo-Dash v0.8.2 [](http://travis-ci.org/bestiejs/lodash) A drop-in replacement[*](https://github.com/bestiejs/lodash/wiki/Drop-in-Disclaimer) for Underscore.js, from the devs behind [jsPerf.com](http://jsperf.com), delivering [performance](http://lodash.com/benchmarks), [bug fixes](https://github.com/bestiejs/lodash#resolved-underscorejs-issues), and [additional features](http://lodash.com/#features). @@ -7,10 +7,10 @@ Lo-Dash’s performance is gained by avoiding slower native methods, instead opt ## Download - * [Development build](https://raw.github.com/bestiejs/lodash/v0.8.1/lodash.js) - * [Production build](https://raw.github.com/bestiejs/lodash/v0.8.1/lodash.min.js) - * [Underscore build](https://raw.github.com/bestiejs/lodash/v0.8.1/lodash.underscore.min.js) tailored for projects already using Underscore - * CDN copies of ≤ [v0.8.1](http://cdnjs.cloudflare.com/ajax/libs/lodash.js/0.8.1/lodash.min.js) are available on [cdnjs](http://cdnjs.com/) thanks to [CloudFlare](http://www.cloudflare.com/) + * [Development build](https://raw.github.com/bestiejs/lodash/v0.8.2/lodash.js) + * [Production build](https://raw.github.com/bestiejs/lodash/v0.8.2/lodash.min.js) + * [Underscore build](https://raw.github.com/bestiejs/lodash/v0.8.2/lodash.underscore.min.js) tailored for projects already using Underscore + * CDN copies of ≤ [v0.8.2](http://cdnjs.cloudflare.com/ajax/libs/lodash.js/0.8.2/lodash.min.js) are available on [cdnjs](http://cdnjs.com/) thanks to [CloudFlare](http://www.cloudflare.com/) * For optimal file size, [create a custom build](https://github.com/bestiejs/lodash#custom-builds) with only the features you need ## Dive in @@ -38,6 +38,7 @@ For more information check out these screencasts over Lo-Dash: * [_.forEach](http://lodash.com/docs#forEach) is chainable and supports exiting iteration early * [_.forIn](http://lodash.com/docs#forIn) for iterating over an object’s own and inherited properties * [_.forOwn](http://lodash.com/docs#forOwn) for iterating over an object’s own properties + * [_.isPlainObject](http://lodash.com/docs#isPlainObject) checks if values are created by the `Object` constructor * [_.lateBind](http://lodash.com/docs#lateBind) for late binding * [_.merge](http://lodash.com/docs#merge) for a *“deep”* [_.extend](http://lodash.com/docs#extend) * [_.partial](http://lodash.com/docs#partial) for partial application without `this` binding @@ -48,7 +49,7 @@ For more information check out these screencasts over Lo-Dash: ## Support -Lo-Dash has been tested in at least Chrome 5-22, Firefox 1-15, IE 6-10, Opera 9.25-12, Safari 3-6, Node.js 0.4.8-0.8.11, Narwhal 0.3.2, RingoJS 0.8, and Rhino 1.7RC5. +Lo-Dash has been tested in at least Chrome 5~22, Firefox 1~16, IE 6-10, Opera 9.25-12, Safari 3-6, Node.js 0.4.8-0.8.11, Narwhal 0.3.2, RingoJS 0.8, and Rhino 1.7RC5. ## Custom builds @@ -161,7 +162,9 @@ Using [npm](http://npmjs.org/): ```bash npm install lodash + npm install -g lodash +npm link lodash ``` In [Node.js](http://nodejs.org/) and [RingoJS v0.8.0+](http://ringojs.org/): @@ -170,6 +173,8 @@ In [Node.js](http://nodejs.org/) and [RingoJS v0.8.0+](http://ringojs.org/): var _ = require('lodash'); ``` +**Note:** If Lo-Dash is installed globally, [run `npm link lodash`](http://blog.nodejs.org/2011/03/23/npm-1-0-global-vs-local-installation/) in your project’s root directory before attempting to `require` it. + In [RingoJS v0.7.0-](http://ringojs.org/): ```js @@ -197,22 +202,20 @@ require({ ## Resolved Underscore.js issues - * Add AMD loader support [[#431](https://github.com/documentcloud/underscore/pull/431), [test](https://github.com/bestiejs/lodash/blob/v0.8.1/test/test.js#L118-140)] - * Allow iteration of objects with a `length` property [[#799](https://github.com/documentcloud/underscore/pull/799), [test](https://github.com/bestiejs/lodash/blob/v0.8.1/test/test.js#L510-516)] - * Ensure *“Arrays”*, *“Collections”*, and *“Objects”* methods don’t error when passed falsey arguments [[#650](https://github.com/documentcloud/underscore/pull/650), [#803](https://github.com/documentcloud/underscore/issues/803), [test](https://github.com/bestiejs/lodash/blob/v0.8.1/test/test.js#L1729-1764)] - * Ensure *“Collections”* methods allow string `collection` arguments [[#247](https://github.com/documentcloud/underscore/issues/247), [#276](https://github.com/documentcloud/underscore/issues/276), [#561](https://github.com/documentcloud/underscore/pull/561), [test](https://github.com/bestiejs/lodash/blob/v0.8.1/test/test.js#L470-487)] - * Fix cross-browser object iteration bugs [[#60](https://github.com/documentcloud/underscore/issues/60), [#376](https://github.com/documentcloud/underscore/issues/376), [test](https://github.com/bestiejs/lodash/blob/v0.8.1/test/test.js#L526-546)] - * Methods should work on pages with incorrectly shimmed native methods [[#7](https://github.com/documentcloud/underscore/issues/7), [#742](https://github.com/documentcloud/underscore/issues/742), [test](https://github.com/bestiejs/lodash/blob/v0.8.1/test/test.js#L142-148)] - * `_.clone` should allow `deep` cloning [[#595](https://github.com/documentcloud/underscore/pull/595), [test](https://github.com/bestiejs/lodash/blob/v0.8.1/test/test.js#L215-224)] - * `_.contains` should work with strings [[#667](https://github.com/documentcloud/underscore/pull/667), [test](https://github.com/bestiejs/lodash/blob/v0.8.1/test/test.js#L267-276)] - * `_.extend` should recursively extend objects [[#379](https://github.com/documentcloud/underscore/pull/379), [#718](https://github.com/documentcloud/underscore/issues/718), [test](https://github.com/bestiejs/lodash/blob/v0.8.1/test/test.js#L955-977)] - * `_.forEach` should be chainable [[#142](https://github.com/documentcloud/underscore/issues/142), [test](https://github.com/bestiejs/lodash/blob/v0.8.1/test/test.js#L465-468)] - * `_.forEach` should allow exiting iteration early [[#211](https://github.com/documentcloud/underscore/issues/211), [test](https://github.com/bestiejs/lodash/blob/v0.8.1/test/test.js#L553-570)] - * `_.isEmpty` should support jQuery/MooTools DOM query collections [[#690](https://github.com/documentcloud/underscore/pull/690), [test](https://github.com/bestiejs/lodash/blob/v0.8.1/test/test.js#L712-717)] - * `_.isObject` should avoid V8 bug [#2291](http://code.google.com/p/v8/issues/detail?id=2291) [[#605](https://github.com/documentcloud/underscore/issues/605), [test](https://github.com/bestiejs/lodash/blob/v0.8.1/test/test.js#L772-784)] - * `_.keys` should work with `arguments` objects cross-browser [[#396](https://github.com/documentcloud/underscore/issues/396), [test](https://github.com/bestiejs/lodash/blob/v0.8.1/test/test.js#L865-867)] - * `_.range` should coerce arguments to numbers [[#634](https://github.com/documentcloud/underscore/issues/634), [#683](https://github.com/documentcloud/underscore/issues/683), [test](https://github.com/bestiejs/lodash/blob/v0.8.1/test/test.js#L1231-1234)] - * `_.throttle` should work when called in a loop [[#502](https://github.com/documentcloud/underscore/issues/502), [test](https://github.com/bestiejs/lodash/blob/v0.8.1/test/test.js#L1549-1559)] + * Add AMD loader support [[#431](https://github.com/documentcloud/underscore/pull/431), [test](https://github.com/bestiejs/lodash/blob/v0.8.2/test/test.js#L118-140)] + * Allow iteration of objects with a `length` property [[#799](https://github.com/documentcloud/underscore/pull/799), [test](https://github.com/bestiejs/lodash/blob/v0.8.2/test/test.js#L510-516)] + * Ensure *“Collections”* methods allow string `collection` arguments [[#247](https://github.com/documentcloud/underscore/issues/247), [#276](https://github.com/documentcloud/underscore/issues/276), [#561](https://github.com/documentcloud/underscore/pull/561), [test](https://github.com/bestiejs/lodash/blob/v0.8.2/test/test.js#L470-487)] + * Fix cross-browser object iteration bugs [[#60](https://github.com/documentcloud/underscore/issues/60), [#376](https://github.com/documentcloud/underscore/issues/376), [test](https://github.com/bestiejs/lodash/blob/v0.8.2/test/test.js#L523-547)] + * Methods should work on pages with incorrectly shimmed native methods [[#7](https://github.com/documentcloud/underscore/issues/7), [#742](https://github.com/documentcloud/underscore/issues/742), [test](https://github.com/bestiejs/lodash/blob/v0.8.2/test/test.js#L142-148)] + * `_.clone` should allow `deep` cloning [[#595](https://github.com/documentcloud/underscore/pull/595), [test](https://github.com/bestiejs/lodash/blob/v0.8.2/test/test.js#L214-225)] + * `_.contains` should work with strings [[#667](https://github.com/documentcloud/underscore/pull/667), [test](https://github.com/bestiejs/lodash/blob/v0.8.2/test/test.js#L267-276)] + * `_.extend` should recursively extend objects [[#379](https://github.com/documentcloud/underscore/pull/379), [#718](https://github.com/documentcloud/underscore/issues/718), [test](https://github.com/bestiejs/lodash/blob/v0.8.2/test/test.js#L968-990)] + * `_.forEach` should be chainable [[#142](https://github.com/documentcloud/underscore/issues/142), [test](https://github.com/bestiejs/lodash/blob/v0.8.2/test/test.js#L465-468)] + * `_.forEach` should allow exiting iteration early [[#211](https://github.com/documentcloud/underscore/issues/211), [test](https://github.com/bestiejs/lodash/blob/v0.8.2/test/test.js#L553-571)] + * `_.isEmpty` should support jQuery/MooTools DOM query collections [[#690](https://github.com/documentcloud/underscore/pull/690), [test](https://github.com/bestiejs/lodash/blob/v0.8.2/test/test.js#L712-717)] + * `_.isObject` should avoid V8 bug [#2291](http://code.google.com/p/v8/issues/detail?id=2291) [[#605](https://github.com/documentcloud/underscore/issues/605), [test](https://github.com/bestiejs/lodash/blob/v0.8.2/test/test.js#L772-784)] + * `_.keys` should work with `arguments` objects cross-browser [[#396](https://github.com/documentcloud/underscore/issues/396), [test](https://github.com/bestiejs/lodash/blob/v0.8.2/test/test.js#L865-867)] + * `_.range` should coerce arguments to numbers [[#634](https://github.com/documentcloud/underscore/issues/634), [#683](https://github.com/documentcloud/underscore/issues/683), [test](https://github.com/bestiejs/lodash/blob/v0.8.2/test/test.js#L1243-1246)] ## Optimized methods (50+) @@ -275,10 +278,13 @@ require({ ## Release Notes -### v0.8.1 +### v0.8.2 - * Made `underscore` build include deep clone when `clone` is requested via `include` or `plus` - * Reverted removal of first argument falsey checks from methods + * Ensured `_.map` returns an array when passed a falsey collection + * Ensured `_.throttle` clears its timeout when `func` is called + * Made `_.max`, `_.min`, `_.shuffle` support iterating objects + * Reduced `createIterator`, `_.clone`, and `_.compact` + * Re-optimized `_.max`, `_.min`, and `_.sortedIndex` The full changelog is available [here](https://github.com/bestiejs/lodash/wiki/Changelog). diff --git a/build.js b/build.js index 211805b937..f0b8caa974 100755 --- a/build.js +++ b/build.js @@ -67,7 +67,7 @@ 'bind': ['isFunction'], 'bindAll': ['bind', 'isFunction'], 'chain': ['mixin'], - 'clone': ['extend', 'forOwn', 'isArguments', 'isPlainObject'], + 'clone': ['extend', 'forEach', 'forOwn', 'isArguments', 'isPlainObject'], 'compact': [], 'compose': [], 'contains': [], @@ -118,10 +118,10 @@ 'lastIndexOf': [], 'lateBind': ['isFunction'], 'map': ['identity'], - 'max': ['identity'], + 'max': ['forEach'], 'memoize': [], 'merge': ['isArray', 'isPlainObject'], - 'min': ['identity'], + 'min': ['forEach'], 'mixin': ['forEach', 'functions'], 'noConflict': [], 'object': [], @@ -138,7 +138,7 @@ 'reject': ['identity'], 'rest': [], 'result': ['isFunction'], - 'shuffle': [], + 'shuffle': ['forEach'], 'size': ['keys'], 'some': ['identity'], 'sortBy': ['identity'], @@ -1035,7 +1035,7 @@ } } if (isLegacy) { - _.each(['isBindFast', 'isKeysFast', 'isStrictFast', 'nativeBind', 'nativeGetPrototypeOf', 'nativeIsArray', 'nativeKeys'], function(varName) { + _.each(['getPrototypeOf', 'isBindFast', 'isKeysFast', 'isStrictFast', 'nativeBind', 'nativeIsArray', 'nativeKeys'], function(varName) { source = replaceVar(source, varName, 'false'); }); @@ -1256,8 +1256,14 @@ }); if (isUnderscore) { + // remove "compiled template cleanup" from `_.template` + source = source.replace(/(?:\s*\/\/.*)*\n *source *=.+?isEvaluating.+?reEmptyStringLeading[\s\S]+?\);/, ''); + source = removeVar(source, 'reEmptyStringLeading'); + source = removeVar(source, 'reEmptyStringMiddle'); + source = removeVar(source, 'reEmptyStringTrailing'); + + // replace `isArguments` and its fallback (function() { - // replace `isArguments` and its fallback var snippet = matchFunction(source, 'isArguments') .replace(/function isArguments/, 'lodash.isArguments = function'); @@ -1272,10 +1278,13 @@ } else { source = removeIsArgumentsFallback(source); - } - // remove `hasDontEnumBug`, `hasObjectSpliceBug`, `iteratesOwnLast`, `noArgsEnum` assignment - source = source.replace(/(?:\n +\/\*[^*]*\*+(?:[^\/][^*]*\*+)*\/)?\n *var hasDontEnumBug\b[\s\S]+?}\(1\)\);\n/, ''); + // remove `hasDontEnumBug`, `hasObjectSpliceBug`, `iteratesOwnLast`, `noArgsEnum` assignment + source = source.replace(/(?:\n +\/\*[^*]*\*+(?:[^\/][^*]*\*+)*\/)?\n *var hasDontEnumBug\b[\s\S]+?}\(1\)\);\n/, ''); + + // remove `hasObjectSpliceBug` fix from the mutator Array functions mixin + source = source.replace(/(?:\s*\/\/.*)*\n( +)if *\(hasObjectSpliceBug[\s\S]+?\n\1}/, ''); + } // remove `iteratesOwnLast` from `isPlainObject` source = source.replace(/(?:\s*\/\/.*)*\n( +)if *\(iteratesOwnLast[\s\S]+?\n\1}/, ''); @@ -1283,9 +1292,6 @@ // remove JScript [[DontEnum]] fix from `_.isEqual` source = source.replace(/(?:\s*\/\/.*)*\n( +)if *\(hasDontEnumBug[\s\S]+?\n\1}/, ''); - // remove `hasObjectSpliceBug` fix from the mutator Array functions mixin - source = source.replace(/(?:\s*\/\/.*)*\n( +)if *\(hasObjectSpliceBug[\s\S]+?\n\1}/, ''); - // remove `noArraySliceOnStrings` from `_.toArray` source = source.replace(/noArraySliceOnStrings *\?[^:]+: *([^)]+)/g, '$1'); @@ -1318,7 +1324,7 @@ .replace(/__p *\+= *' *';/g, '') .replace(/(__p *\+= *)' *' *\+/g, '$1') .replace(/(\{) *;|; *(\})/g, '$1$2') - .replace(/\(\(__t *= *\( *([^)]+) *\)\) *== *null *\? *'' *: *__t\)/g, '$1'); + .replace(/\(\(__t *= *\( *([^)]+) *\)\) *== *null *\? *'' *: *__t\)/g, '($1)'); // remove the with-statement snippet = snippet.replace(/ *with *\(.+?\) *{/, '\n').replace(/}([^}]*}[^}]*$)/, '$1'); @@ -1422,7 +1428,7 @@ source = removeVar(source, 'nativeIsArray'); } if (isRemoved(source, 'isPlainObject')) { - source = removeVar(source, 'nativeGetPrototypeOf'); + source = removeVar(source, 'getPrototypeOf'); } if (isRemoved(source, 'keys')) { source = removeFunction(source, 'shimKeys'); diff --git a/build/post-compile.js b/build/post-compile.js index 99429b9ecc..5d616c77b5 100644 --- a/build/post-compile.js +++ b/build/post-compile.js @@ -10,7 +10,7 @@ 'lodash': '/*!\n' + ' Lo-Dash @VERSION lodash.com/license\n' + - ' Underscore.js 1.4.1 underscorejs.org/LICENSE\n' + + ' Underscore.js 1.4.2 underscorejs.org/LICENSE\n' + '*/', 'underscore': '/*! Underscore.js @VERSION underscorejs.org/LICENSE */' diff --git a/doc/README.md b/doc/README.md index af2222c9ea..4121653823 100644 --- a/doc/README.md +++ b/doc/README.md @@ -1,57 +1,118 @@ -# Lo-Dash v0.8.1 +# Lo-Dash v0.8.2 -## `_` +## `Arrays` +* [`_.compact`](#_compactarray) +* [`_.difference`](#_differencearray--array1-array2-) +* [`_.drop`](#_restarray--n) +* [`_.first`](#_firstarray--n) +* [`_.flatten`](#_flattenarray-shallow) +* [`_.head`](#_firstarray--n) +* [`_.indexOf`](#_indexofarray-value--fromindex0) +* [`_.initial`](#_initialarray--n) +* [`_.intersection`](#_intersectionarray1-array2-) +* [`_.last`](#_lastarray--n) +* [`_.lastIndexOf`](#_lastindexofarray-value--fromindexarraylength-1) +* [`_.object`](#_objectkeys--values) +* [`_.range`](#_rangestart0-end--step1) +* [`_.rest`](#_restarray--n) +* [`_.sortedIndex`](#_sortedindexarray-value--callbackidentityproperty-thisarg) +* [`_.tail`](#_restarray--n) +* [`_.take`](#_firstarray--n) +* [`_.union`](#_unionarray1-array2-) +* [`_.uniq`](#_uniqarray--issortedfalse-callbackidentity-thisarg) +* [`_.unique`](#_uniqarray--issortedfalse-callbackidentity-thisarg) +* [`_.without`](#_withoutarray--value1-value2-) +* [`_.zip`](#_ziparray1-array2-) + + + + + + +## `Chaining` * [`_`](#_value) -* [`_.VERSION`](#_version) -* [`_.after`](#_aftern-func) +* [`_.chain`](#_chainvalue) +* [`_.tap`](#_tapvalue-interceptor) +* [`_.prototype.chain`](#_prototypechain) +* [`_.prototype.value`](#_prototypevalue) + + + + + + +## `Collections` * [`_.all`](#_everycollection--callbackidentity-thisarg) * [`_.any`](#_somecollection--callbackidentity-thisarg) -* [`_.bind`](#_bindfunc--thisarg-arg1-arg2-) -* [`_.bindAll`](#_bindallobject--methodname1-methodname2-) -* [`_.chain`](#_chainvalue) -* [`_.clone`](#_clonevalue-deep) * [`_.collect`](#_mapcollection--callbackidentity-thisarg) -* [`_.compact`](#_compactarray) -* [`_.compose`](#_composefunc1-func2-) * [`_.contains`](#_containscollection-target) * [`_.countBy`](#_countbycollection-callbackproperty--thisarg) -* [`_.debounce`](#_debouncefunc-wait-immediate) -* [`_.defaults`](#_defaultsobject--default1-default2-) -* [`_.defer`](#_deferfunc--arg1-arg2-) -* [`_.delay`](#_delayfunc-wait--arg1-arg2-) * [`_.detect`](#_findcollection-callback--thisarg) -* [`_.difference`](#_differencearray--array1-array2-) -* [`_.drop`](#_restarray--n) * [`_.each`](#_foreachcollection-callback--thisarg) -* [`_.escape`](#_escapestring) * [`_.every`](#_everycollection--callbackidentity-thisarg) -* [`_.extend`](#_extendobject--source1-source2-) * [`_.filter`](#_filtercollection--callbackidentity-thisarg) * [`_.find`](#_findcollection-callback--thisarg) -* [`_.first`](#_firstarray--n) -* [`_.flatten`](#_flattenarray-shallow) * [`_.foldl`](#_reducecollection-callback--accumulator-thisarg) * [`_.foldr`](#_reducerightcollection-callback--accumulator-thisarg) * [`_.forEach`](#_foreachcollection-callback--thisarg) +* [`_.groupBy`](#_groupbycollection-callbackproperty--thisarg) +* [`_.include`](#_containscollection-target) +* [`_.inject`](#_reducecollection-callback--accumulator-thisarg) +* [`_.invoke`](#_invokecollection-methodname--arg1-arg2-) +* [`_.map`](#_mapcollection--callbackidentity-thisarg) +* [`_.max`](#_maxcollection--callback-thisarg) +* [`_.min`](#_mincollection--callback-thisarg) +* [`_.pluck`](#_pluckcollection-property) +* [`_.reduce`](#_reducecollection-callback--accumulator-thisarg) +* [`_.reduceRight`](#_reducerightcollection-callback--accumulator-thisarg) +* [`_.reject`](#_rejectcollection--callbackidentity-thisarg) +* [`_.select`](#_filtercollection--callbackidentity-thisarg) +* [`_.shuffle`](#_shufflecollection) +* [`_.size`](#_sizecollection) +* [`_.some`](#_somecollection--callbackidentity-thisarg) +* [`_.sortBy`](#_sortbycollection-callbackproperty--thisarg) +* [`_.toArray`](#_toarraycollection) +* [`_.where`](#_wherecollection-properties) + + + + + + +## `Functions` +* [`_.after`](#_aftern-func) +* [`_.bind`](#_bindfunc--thisarg-arg1-arg2-) +* [`_.bindAll`](#_bindallobject--methodname1-methodname2-) +* [`_.compose`](#_composefunc1-func2-) +* [`_.debounce`](#_debouncefunc-wait-immediate) +* [`_.defer`](#_deferfunc--arg1-arg2-) +* [`_.delay`](#_delayfunc-wait--arg1-arg2-) +* [`_.lateBind`](#_latebindobject-methodname--arg1-arg2-) +* [`_.memoize`](#_memoizefunc--resolver) +* [`_.once`](#_oncefunc) +* [`_.partial`](#_partialfunc--arg1-arg2-) +* [`_.throttle`](#_throttlefunc-wait) +* [`_.wrap`](#_wrapvalue-wrapper) + + + + + + +## `Objects` +* [`_.clone`](#_clonevalue-deep) +* [`_.defaults`](#_defaultsobject--default1-default2-) +* [`_.extend`](#_extendobject--source1-source2-) * [`_.forIn`](#_forinobject-callback--thisarg) * [`_.forOwn`](#_forownobject-callback--thisarg) * [`_.functions`](#_functionsobject) -* [`_.groupBy`](#_groupbycollection-callbackproperty--thisarg) * [`_.has`](#_hasobject-property) -* [`_.head`](#_firstarray--n) -* [`_.identity`](#_identityvalue) -* [`_.include`](#_containscollection-target) -* [`_.indexOf`](#_indexofarray-value--fromindex0) -* [`_.initial`](#_initialarray--n) -* [`_.inject`](#_reducecollection-callback--accumulator-thisarg) -* [`_.intersection`](#_intersectionarray1-array2-) * [`_.invert`](#_invertobject) -* [`_.invoke`](#_invokecollection-methodname--arg1-arg2-) * [`_.isArguments`](#_isargumentsvalue) * [`_.isArray`](#_isarrayvalue) * [`_.isBoolean`](#_isbooleanvalue) @@ -70,70 +131,37 @@ * [`_.isString`](#_isstringvalue) * [`_.isUndefined`](#_isundefinedvalue) * [`_.keys`](#_keysobject) -* [`_.last`](#_lastarray--n) -* [`_.lastIndexOf`](#_lastindexofarray-value--fromindexarraylength-1) -* [`_.lateBind`](#_latebindobject-methodname--arg1-arg2-) -* [`_.map`](#_mapcollection--callbackidentity-thisarg) -* [`_.max`](#_maxarray--callback-thisarg) -* [`_.memoize`](#_memoizefunc--resolver) * [`_.merge`](#_mergeobject--source1-source2-) * [`_.methods`](#_functionsobject) -* [`_.min`](#_minarray--callback-thisarg) -* [`_.mixin`](#_mixinobject) -* [`_.noConflict`](#_noconflict) -* [`_.object`](#_objectkeys--values) * [`_.omit`](#_omitobject-callback-prop1-prop2--thisarg) -* [`_.once`](#_oncefunc) * [`_.pairs`](#_pairsobject) -* [`_.partial`](#_partialfunc--arg1-arg2-) * [`_.pick`](#_pickobject-callback-prop1-prop2--thisarg) -* [`_.pluck`](#_pluckcollection-property) -* [`_.random`](#_randommin0-max1) -* [`_.range`](#_rangestart0-end--step1) -* [`_.reduce`](#_reducecollection-callback--accumulator-thisarg) -* [`_.reduceRight`](#_reducerightcollection-callback--accumulator-thisarg) -* [`_.reject`](#_rejectcollection--callbackidentity-thisarg) -* [`_.rest`](#_restarray--n) -* [`_.result`](#_resultobject-property) -* [`_.select`](#_filtercollection--callbackidentity-thisarg) -* [`_.shuffle`](#_shufflearray) -* [`_.size`](#_sizecollection) -* [`_.some`](#_somecollection--callbackidentity-thisarg) -* [`_.sortBy`](#_sortbycollection-callbackproperty--thisarg) -* [`_.sortedIndex`](#_sortedindexarray-value--callbackidentityproperty-thisarg) -* [`_.tail`](#_restarray--n) -* [`_.take`](#_firstarray--n) -* [`_.tap`](#_tapvalue-interceptor) -* [`_.template`](#_templatetext-data-options) -* [`_.throttle`](#_throttlefunc-wait) -* [`_.times`](#_timesn-callback--thisarg) -* [`_.toArray`](#_toarraycollection) -* [`_.unescape`](#_unescapestring) -* [`_.union`](#_unionarray1-array2-) -* [`_.uniq`](#_uniqarray--issortedfalse-callbackidentity-thisarg) -* [`_.unique`](#_uniqarray--issortedfalse-callbackidentity-thisarg) -* [`_.uniqueId`](#_uniqueidprefix) * [`_.values`](#_valuesobject) -* [`_.where`](#_wherecollection-properties) -* [`_.without`](#_withoutarray--value1-value2-) -* [`_.wrap`](#_wrapvalue-wrapper) -* [`_.zip`](#_ziparray1-array2-) -## `_.prototype` -* [`_.prototype.chain`](#_prototypechain) -* [`_.prototype.value`](#_prototypevalue) +## `Utilities` +* [`_.escape`](#_escapestring) +* [`_.identity`](#_identityvalue) +* [`_.mixin`](#_mixinobject) +* [`_.noConflict`](#_noconflict) +* [`_.random`](#_randommin0-max1) +* [`_.result`](#_resultobject-property) +* [`_.template`](#_templatetext-data-options) +* [`_.times`](#_timesn-callback--thisarg) +* [`_.unescape`](#_unescapestring) +* [`_.uniqueId`](#_uniqueidprefix) -## `_.templateSettings` +## `Properties` +* [`_.VERSION`](#_version) * [`_.templateSettings`](#_templatesettings) * [`_.templateSettings.escape`](#_templatesettingsescape) * [`_.templateSettings.evaluate`](#_templatesettingsevaluate) @@ -151,20 +179,26 @@ -## `_` +## `“Arrays” Methods` -### `_(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L241 "View in source") [Ⓣ][1] +### `_.compact(array)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2511 "View in source") [Ⓣ][1] -The `lodash` function. +Creates an array with all falsey values of `array` removed. The values `false`, `null`, `0`, `""`, `undefined` and `NaN` are all falsey. #### Arguments -1. `value` *(Mixed)*: The value to wrap in a `lodash` instance. +1. `array` *(Array)*: The array to compact. #### Returns -*(Object)*: Returns a `lodash` instance. +*(Array)*: Returns a new filtered array. + +#### Example +```js +_.compact([0, 1, false, 2, '', 3]); +// => [1, 2, 3] +``` * * * @@ -173,10 +207,23 @@ The `lodash` function. -### `_.VERSION` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4002 "View in source") [Ⓣ][1] +### `_.difference(array [, array1, array2, ...])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2541 "View in source") [Ⓣ][1] -*(String)*: The semantic version number. +Creates an array of `array` elements not present in the other arrays using strict equality for comparisons, i.e. `===`. + +#### Arguments +1. `array` *(Array)*: The array to process. +2. `[array1, array2, ...]` *(Array)*: Arrays to check. + +#### Returns +*(Array)*: Returns a new array of `array` elements not present in the other arrays. + +#### Example +```js +_.difference([1, 2, 3, 4, 5], [5, 2, 10]); +// => [1, 3, 4] +``` * * * @@ -185,25 +232,25 @@ The `lodash` function. -### `_.after(n, func)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3108 "View in source") [Ⓣ][1] +### `_.first(array [, n])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2579 "View in source") [Ⓣ][1] -Creates a function that is restricted to executing only after it is called `n` times. +Gets the first element of the `array`. Pass `n` to return the first `n` elements of the `array`. + +#### Aliases +*head, take* #### Arguments -1. `n` *(Number)*: The number of times the function must be called before it is executed. -2. `func` *(Function)*: The function to restrict. +1. `array` *(Array)*: The array to query. +2. `[n]` *(Number)*: The number of elements to return. #### Returns -*(Function)*: Returns the new restricted function. +*(Mixed)*: Returns the first element or an array of the first `n` elements of `array`. #### Example ```js -var renderNotes = _.after(notes.length, render); -_.forEach(notes, function(note) { - note.asyncSave({ 'success': renderNotes }); -}); -// `renderNotes` is run once, after all notes have saved +_.first([5, 4, 3, 2, 1]); +// => 5 ``` * * * @@ -213,28 +260,25 @@ _.forEach(notes, function(note) { -### `_.bind(func [, thisArg, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3141 "View in source") [Ⓣ][1] +### `_.flatten(array, shallow)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2603 "View in source") [Ⓣ][1] -Creates a function that, when called, invokes `func` with the `this` binding of `thisArg` and prepends any additional `bind` arguments to those passed to the bound function. +Flattens a nested array *(the nesting can be to any depth)*. If `shallow` is truthy, `array` will only be flattened a single level. #### Arguments -1. `func` *(Function)*: The function to bind. -2. `[thisArg]` *(Mixed)*: The `this` binding of `func`. -3. `[arg1, arg2, ...]` *(Mixed)*: Arguments to be partially applied. +1. `array` *(Array)*: The array to compact. +2. `shallow` *(Boolean)*: A flag to indicate only flattening a single level. #### Returns -*(Function)*: Returns the new bound function. +*(Array)*: Returns a new flattened array. #### Example ```js -var func = function(greeting) { - return greeting + ' ' + this.name; -}; +_.flatten([1, [2], [3, [[4]]]]); +// => [1, 2, 3, 4]; -func = _.bind(func, { 'name': 'moe' }, 'hi'); -func(); -// => 'hi moe' +_.flatten([1, [2], [3, [[4]]]], true); +// => [1, 2, 3, [[4]]]; ``` * * * @@ -244,28 +288,29 @@ func(); -### `_.bindAll(object [, methodName1, methodName2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3171 "View in source") [Ⓣ][1] +### `_.indexOf(array, value [, fromIndex=0])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2645 "View in source") [Ⓣ][1] -Binds methods on `object` to `object`, overwriting the existing method. If no method names are provided, all the function properties of `object` will be bound. +Gets the index at which the first occurrence of `value` is found using strict equality for comparisons, i.e. `===`. If the `array` is already sorted, passing `true` for `fromIndex` will run a faster binary search. #### Arguments -1. `object` *(Object)*: The object to bind and assign the bound methods to. -2. `[methodName1, methodName2, ...]` *(String)*: Method names on the object to bind. +1. `array` *(Array)*: The array to search. +2. `value` *(Mixed)*: The value to search for. +3. `[fromIndex=0]` *(Boolean|Number)*: The index to start searching from or `true` to perform a binary search on a sorted `array`. #### Returns -*(Object)*: Returns `object`. +*(Number)*: Returns the index of the matched value or `-1`. #### Example ```js -var buttonView = { - 'label': 'lodash', - 'onClick': function() { alert('clicked: ' + this.label); } -}; +_.indexOf([1, 2, 3, 1, 2, 3], 2); +// => 1 -_.bindAll(buttonView); -jQuery('#lodash_button').on('click', buttonView.onClick); -// => When the button is clicked, `this.label` will have the correct value +_.indexOf([1, 2, 3, 1, 2, 3], 2, 3); +// => 4 + +_.indexOf([1, 1, 2, 2, 3, 3], 2, true); +// => 2 ``` * * * @@ -275,31 +320,46 @@ jQuery('#lodash_button').on('click', buttonView.onClick); -### `_.chain(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3927 "View in source") [Ⓣ][1] +### `_.initial(array [, n])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2680 "View in source") [Ⓣ][1] -Wraps the value in a `lodash` wrapper object. +Gets all but the last element of `array`. Pass `n` to exclude the last `n` elements from the result. #### Arguments -1. `value` *(Mixed)*: The value to wrap. +1. `array` *(Array)*: The array to query. +2. `[n]` *(Number)*: The number of elements to return. #### Returns -*(Object)*: Returns the wrapper object. +*(Array)*: Returns all but the last element or `n` elements of `array`. #### Example ```js -var stooges = [ - { 'name': 'moe', 'age': 40 }, - { 'name': 'larry', 'age': 50 }, - { 'name': 'curly', 'age': 60 } -]; +_.initial([3, 2, 1]); +// => [3, 2] +``` -var youngest = _.chain(stooges) - .sortBy(function(stooge) { return stooge.age; }) - .map(function(stooge) { return stooge.name + ' is ' + stooge.age; }) - .first() - .value(); -// => 'moe is 40' +* * * + + + + + + +### `_.intersection([array1, array2, ...])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2701 "View in source") [Ⓣ][1] + +Computes the intersection of all the passed-in arrays using strict equality for comparisons, i.e. `===`. + +#### Arguments +1. `[array1, array2, ...]` *(Array)*: Arrays to process. + +#### Returns +*(Array)*: Returns a new array of unique elements, in order, that are present in **all** of the arrays. + +#### Example +```js +_.intersection([1, 2, 3], [101, 2, 1, 10], [2, 1]); +// => [1, 2] ``` * * * @@ -309,36 +369,51 @@ var youngest = _.chain(stooges) -### `_.clone(value, deep)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1039 "View in source") [Ⓣ][1] +### `_.last(array [, n])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2740 "View in source") [Ⓣ][1] -Creates a clone of `value`. If `deep` is `true`, all nested objects will also be cloned otherwise they will be assigned by reference. Functions, DOM nodes, `arguments` objects, and objects created by constructors other than `Object` are **not** cloned. +Gets the last element of the `array`. Pass `n` to return the last `n` elements of the `array`. #### Arguments -1. `value` *(Mixed)*: The value to clone. -2. `deep` *(Boolean)*: A flag to indicate a deep clone. +1. `array` *(Array)*: The array to query. +2. `[n]` *(Number)*: The number of elements to return. #### Returns -*(Mixed)*: Returns the cloned `value`. +*(Mixed)*: Returns the last element or an array of the last `n` elements of `array`. #### Example ```js -var stooges = [ - { 'name': 'moe', 'age': 40 }, - { 'name': 'larry', 'age': 50 }, - { 'name': 'curly', 'age': 60 } -]; +_.last([3, 2, 1]); +// => 1 +``` -_.clone({ 'name': 'moe' }); -// => { 'name': 'moe' } +* * * -var shallow = _.clone(stooges); -shallow[0] === stooges[0]; -// => true + -var deep = _.clone(stooges, true); -shallow[0] === stooges[0]; -// => false + + + +### `_.lastIndexOf(array, value [, fromIndex=array.length-1])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2766 "View in source") [Ⓣ][1] + +Gets the index at which the last occurrence of `value` is found using strict equality for comparisons, i.e. `===`. + +#### Arguments +1. `array` *(Array)*: The array to search. +2. `value` *(Mixed)*: The value to search for. +3. `[fromIndex=array.length-1]` *(Number)*: The index to start searching from. + +#### Returns +*(Number)*: Returns the index of the matched value or `-1`. + +#### Example +```js +_.lastIndexOf([1, 2, 3, 1, 2, 3], 2); +// => 4 + +_.lastIndexOf([1, 2, 3, 1, 2, 3], 2, 3); +// => 1 ``` * * * @@ -348,21 +423,22 @@ shallow[0] === stooges[0]; -### `_.compact(array)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2413 "View in source") [Ⓣ][1] +### `_.object(keys [, values=[]])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2796 "View in source") [Ⓣ][1] -Creates an array with all falsey values of `array` removed. The values `false`, `null`, `0`, `""`, `undefined` and `NaN` are all falsey. +Creates an object composed from arrays of `keys` and `values`. Pass either a single two dimensional array, i.e. `[[key1, value1], [key2, value2]]`, or two arrays, one of `keys` and one of corresponding `values`. #### Arguments -1. `array` *(Array)*: The array to compact. +1. `keys` *(Array)*: The array of keys. +2. `[values=[]]` *(Array)*: The array of values. #### Returns -*(Array)*: Returns a new filtered array. +*(Object)*: Returns an object composed of the given keys and corresponding values. #### Example ```js -_.compact([0, 1, false, 2, '', 3]); -// => [1, 2, 3] +_.object(['moe', 'larry', 'curly'], [30, 40, 50]); +// => { 'moe': 30, 'larry': 40, 'curly': 50 } ``` * * * @@ -372,24 +448,35 @@ _.compact([0, 1, false, 2, '', 3]); -### `_.compose([func1, func2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3208 "View in source") [Ⓣ][1] +### `_.range([start=0], end [, step=1])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2841 "View in source") [Ⓣ][1] -Creates a function that is the composition of the passed functions, where each function consumes the return value of the function that follows. In math terms, composing the functions `f()`, `g()`, and `h()` produces `f(g(h()))`. +Creates an array of numbers *(positive and/or negative)* progressing from `start` up to but not including `stop`. This method is a port of Python's `range()` function. See http://docs.python.org/library/functions.html#range. #### Arguments -1. `[func1, func2, ...]` *(Function)*: Functions to compose. +1. `[start=0]` *(Number)*: The start of the range. +2. `end` *(Number)*: The end of the range. +3. `[step=1]` *(Number)*: The value to increment or descrement by. #### Returns -*(Function)*: Returns the new composed function. +*(Array)*: Returns a new range array. #### Example ```js -var greet = function(name) { return 'hi: ' + name; }; -var exclaim = function(statement) { return statement + '!'; }; -var welcome = _.compose(exclaim, greet); -welcome('moe'); -// => 'hi: moe!' +_.range(10); +// => [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] + +_.range(1, 11); +// => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] + +_.range(0, 30, 5); +// => [0, 5, 10, 15, 20, 25] + +_.range(0, -10, -1); +// => [0, -1, -2, -3, -4, -5, -6, -7, -8, -9] + +_.range(0); +// => [] ``` * * * @@ -399,31 +486,25 @@ welcome('moe'); -### `_.contains(collection, target)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1892 "View in source") [Ⓣ][1] +### `_.rest(array [, n])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2880 "View in source") [Ⓣ][1] -Checks if a given `target` element is present in a `collection` using strict equality for comparisons, i.e. `===`. +The opposite of `_.initial`, this method gets all but the first value of `array`. Pass `n` to exclude the first `n` values from the result. #### Aliases -*include* +*drop, tail* #### Arguments -1. `collection` *(Array|Object|String)*: The collection to iterate over. -2. `target` *(Mixed)*: The value to check for. +1. `array` *(Array)*: The array to query. +2. `[n]` *(Number)*: The number of elements to return. #### Returns -*(Boolean)*: Returns `true` if the `target` element is found, else `false`. +*(Array)*: Returns all but the first value or `n` values of `array`. #### Example ```js -_.contains([1, 2, 3], 3); -// => true - -_.contains({ 'name': 'moe', 'age': 40 }, 'moe'); -// => true - -_.contains('curly', 'ur'); -// => true +_.rest([3, 2, 1]); +// => [2, 1] ``` * * * @@ -433,29 +514,41 @@ _.contains('curly', 'ur'); -### `_.countBy(collection, callback|property [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1928 "View in source") [Ⓣ][1] +### `_.sortedIndex(array, value [, callback=identity|property, thisArg])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2926 "View in source") [Ⓣ][1] -Creates an object composed of keys returned from running each element of `collection` through a `callback`. The corresponding value of each key is the number of times the key was returned by `callback`. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. The `callback` argument may also be the name of a property to count by *(e.g. 'length')*. +Uses a binary search to determine the smallest index at which the `value` should be inserted into `array` in order to maintain the sort order of the sorted `array`. If `callback` is passed, it will be executed for `value` and each element in `array` to compute their sort ranking. The `callback` is bound to `thisArg` and invoked with one argument; *(value)*. The `callback` argument may also be the name of a property to order by. #### Arguments -1. `collection` *(Array|Object|String)*: The collection to iterate over. -2. `callback|property` *(Function|String)*: The function called per iteration or property name to count by. -3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. +1. `array` *(Array)*: The array to iterate over. +2. `value` *(Mixed)*: The value to evaluate. +3. `[callback=identity|property]` *(Function|String)*: The function called per iteration or property name to order by. +4. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. #### Returns -*(Object)*: Returns the composed aggregate object. +*(Number)*: Returns the index at which the value should be inserted into `array`. #### Example ```js -_.countBy([4.3, 6.1, 6.4], function(num) { return Math.floor(num); }); -// => { '4': 1, '6': 2 } +_.sortedIndex([20, 30, 50], 40); +// => 2 -_.countBy([4.3, 6.1, 6.4], function(num) { return this.floor(num); }, Math); -// => { '4': 1, '6': 2 } +_.sortedIndex([{ 'x': 20 }, { 'x': 30 }, { 'x': 50 }], { 'x': 40 }, 'x'); +// => 2 -_.countBy(['one', 'two', 'three'], 'length'); -// => { '3': 2, '5': 1 } +var dict = { + 'wordToNumber': { 'twenty': 20, 'thirty': 30, 'fourty': 40, 'fifty': 50 } +}; + +_.sortedIndex(['twenty', 'thirty', 'fifty'], 'fourty', function(word) { + return dict.wordToNumber[word]; +}); +// => 2 + +_.sortedIndex(['twenty', 'thirty', 'fifty'], 'fourty', function(word) { + return this.wordToNumber[word]; +}, dict); +// => 2 ``` * * * @@ -465,23 +558,21 @@ _.countBy(['one', 'two', 'three'], 'length'); -### `_.debounce(func, wait, immediate)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3241 "View in source") [Ⓣ][1] +### `_.union([array1, array2, ...])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2961 "View in source") [Ⓣ][1] -Creates a function that will delay the execution of `func` until after `wait` milliseconds have elapsed since the last time it was invoked. Pass `true` for `immediate` to cause debounce to invoke `func` on the leading, instead of the trailing, edge of the `wait` timeout. Subsequent calls to the debounced function will return the result of the last `func` call. +Computes the union of the passed-in arrays using strict equality for comparisons, i.e. `===`. #### Arguments -1. `func` *(Function)*: The function to debounce. -2. `wait` *(Number)*: The number of milliseconds to delay. -3. `immediate` *(Boolean)*: A flag to indicate execution is on the leading edge of the timeout. +1. `[array1, array2, ...]` *(Array)*: Arrays to process. #### Returns -*(Function)*: Returns the new debounced function. +*(Array)*: Returns a new array of unique values, in order, that are present in one or more of the arrays. #### Example ```js -var lazyLayout = _.debounce(calculateLayout, 300); -jQuery(window).on('resize', lazyLayout); +_.union([1, 2, 3], [101, 2, 1, 10], [2, 1]); +// => [1, 2, 3, 101, 10] ``` * * * @@ -491,23 +582,36 @@ jQuery(window).on('resize', lazyLayout); -### `_.defaults(object [, default1, default2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1132 "View in source") [Ⓣ][1] +### `_.uniq(array [, isSorted=false, callback=identity, thisArg])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3006 "View in source") [Ⓣ][1] -Assigns enumerable properties of the default object(s) to the `destination` object for all `destination` properties that resolve to `null`/`undefined`. Once a property is set, additional defaults of the same property will be ignored. +Creates a duplicate-value-free version of the `array` using strict equality for comparisons, i.e. `===`. If the `array` is already sorted, passing `true` for `isSorted` will run a faster algorithm. If `callback` is passed, each element of `array` is passed through a callback` before uniqueness is computed. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index, array)*. + +#### Aliases +*unique* #### Arguments -1. `object` *(Object)*: The destination object. -2. `[default1, default2, ...]` *(Object)*: The default objects. +1. `array` *(Array)*: The array to process. +2. `[isSorted=false]` *(Boolean)*: A flag to indicate that the `array` is already sorted. +3. `[callback=identity]` *(Function)*: The function called per iteration. +4. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. #### Returns -*(Object)*: Returns the destination object. +*(Array)*: Returns a duplicate-value-free array. #### Example ```js -var iceCream = { 'flavor': 'chocolate' }; -_.defaults(iceCream, { 'flavor': 'vanilla', 'sprinkles': 'rainbow' }); -// => { 'flavor': 'chocolate', 'sprinkles': 'rainbow' } +_.uniq([1, 2, 1, 3, 1]); +// => [1, 2, 3] + +_.uniq([1, 1, 2, 2, 3], true); +// => [1, 2, 3] + +_.uniq([1, 2, 1.5, 3, 2.5], function(num) { return Math.floor(num); }); +// => [1, 2, 3] + +_.uniq([1, 2, 1.5, 3, 2.5], function(num) { return this.floor(num); }, Math); +// => [1, 2, 3] ``` * * * @@ -517,22 +621,22 @@ _.defaults(iceCream, { 'flavor': 'vanilla', 'sprinkles': 'rainbow' }); -### `_.defer(func [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3306 "View in source") [Ⓣ][1] +### `_.without(array [, value1, value2, ...])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3047 "View in source") [Ⓣ][1] -Defers executing the `func` function until the current call stack has cleared. Additional arguments will be passed to `func` when it is invoked. +Creates an array with all occurrences of the passed values removed using strict equality for comparisons, i.e. `===`. #### Arguments -1. `func` *(Function)*: The function to defer. -2. `[arg1, arg2, ...]` *(Mixed)*: Arguments to invoke the function with. +1. `array` *(Array)*: The array to filter. +2. `[value1, value2, ...]` *(Mixed)*: Values to remove. #### Returns -*(Number)*: Returns the `setTimeout` timeout id. +*(Array)*: Returns a new filtered array. #### Example ```js -_.defer(function() { alert('deferred'); }); -// returns from the function before `alert` is called +_.without([1, 2, 1, 0, 3, 1, 4], 0, 1); +// => [2, 3, 4] ``` * * * @@ -542,24 +646,21 @@ _.defer(function() { alert('deferred'); }); -### `_.delay(func, wait [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3286 "View in source") [Ⓣ][1] +### `_.zip([array1, array2, ...])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3078 "View in source") [Ⓣ][1] -Executes the `func` function after `wait` milliseconds. Additional arguments will be passed to `func` when it is invoked. +Groups the elements of each array at their corresponding indexes. Useful for separate data sources that are coordinated through matching array indexes. For a matrix of nested arrays, `_.zip.apply(...)` can transpose the matrix in a similar fashion. #### Arguments -1. `func` *(Function)*: The function to delay. -2. `wait` *(Number)*: The number of milliseconds to delay execution. -3. `[arg1, arg2, ...]` *(Mixed)*: Arguments to invoke the function with. +1. `[array1, array2, ...]` *(Array)*: Arrays to process. #### Returns -*(Number)*: Returns the `setTimeout` timeout id. +*(Array)*: Returns a new array of grouped elements. #### Example ```js -var log = _.bind(console.log, console); -_.delay(log, 1000, 'logged later'); -// => 'logged later' (Appears after one second.) +_.zip(['moe', 'larry', 'curly'], [30, 40, 50], [true, false, false]); +// => [['moe', 30, true], ['larry', 40, false], ['curly', 50, false]] ``` * * * @@ -567,49 +668,25 @@ _.delay(log, 1000, 'logged later'); - - -### `_.difference(array [, array1, array2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2442 "View in source") [Ⓣ][1] - -Creates an array of `array` elements not present in the other arrays using strict equality for comparisons, i.e. `===`. - -#### Arguments -1. `array` *(Array)*: The array to process. -2. `[array1, array2, ...]` *(Array)*: Arrays to check. - -#### Returns -*(Array)*: Returns a new array of `array` elements not present in the other arrays. - -#### Example -```js -_.difference([1, 2, 3, 4, 5], [5, 2, 10]); -// => [1, 3, 4] -``` + -* * * - + +## `“Chaining” Methods` -### `_.escape(string)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3526 "View in source") [Ⓣ][1] +### `_(value)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L243 "View in source") [Ⓣ][1] -Converts the characters `&`, `<`, `>`, `"`, and `'` in `string` to their corresponding HTML entities. +The `lodash` function. #### Arguments -1. `string` *(String)*: The string to escape. +1. `value` *(Mixed)*: The value to wrap in a `lodash` instance. #### Returns -*(String)*: Returns the escaped string. - -#### Example -```js -_.escape('Moe, Larry & Curly'); -// => "Moe, Larry & Curly" -``` +*(Object)*: Returns a `lodash` instance. * * * @@ -618,26 +695,31 @@ _.escape('Moe, Larry & Curly'); -### `_.every(collection [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1949 "View in source") [Ⓣ][1] - -Checks if the `callback` returns a truthy value for **all** elements of a `collection`. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. +### `_.chain(value)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3929 "View in source") [Ⓣ][1] -#### Aliases -*all* +Wraps the value in a `lodash` wrapper object. #### Arguments -1. `collection` *(Array|Object|String)*: The collection to iterate over. -2. `[callback=identity]` *(Function)*: The function called per iteration. -3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. +1. `value` *(Mixed)*: The value to wrap. #### Returns -*(Boolean)*: Returns `true` if all elements pass the callback check, else `false`. +*(Object)*: Returns the wrapper object. #### Example ```js -_.every([true, 1, null, 'yes'], Boolean); -// => false +var stooges = [ + { 'name': 'moe', 'age': 40 }, + { 'name': 'larry', 'age': 50 }, + { 'name': 'curly', 'age': 60 } +]; + +var youngest = _.chain(stooges) + .sortBy(function(stooge) { return stooge.age; }) + .map(function(stooge) { return stooge.name + ' is ' + stooge.age; }) + .first() + .value(); +// => 'moe is 40' ``` * * * @@ -647,22 +729,27 @@ _.every([true, 1, null, 'yes'], Boolean); -### `_.extend(object [, source1, source2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1152 "View in source") [Ⓣ][1] +### `_.tap(value, interceptor)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3956 "View in source") [Ⓣ][1] -Assigns enumerable properties of the source object(s) to the `destination` object. Subsequent sources will overwrite propery assignments of previous sources. +Invokes `interceptor` with the `value` as the first argument, and then returns `value`. The purpose of this method is to "tap into" a method chain, in order to perform operations on intermediate results within the chain. #### Arguments -1. `object` *(Object)*: The destination object. -2. `[source1, source2, ...]` *(Object)*: The source objects. +1. `value` *(Mixed)*: The value to pass to `interceptor`. +2. `interceptor` *(Function)*: The function to invoke. #### Returns -*(Object)*: Returns the destination object. +*(Mixed)*: Returns `value`. #### Example ```js -_.extend({ 'name': 'moe' }, { 'age': 40 }); -// => { 'name': 'moe', 'age': 40 } +_.chain([1, 2, 3, 200]) + .filter(function(num) { return num % 2 == 0; }) + .tap(alert) + .map(function(num) { return num * num }) + .value(); +// => // [2, 200] (alerted) +// => [4, 40000] ``` * * * @@ -672,26 +759,18 @@ _.extend({ 'name': 'moe' }, { 'age': 40 }); -### `_.filter(collection [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1969 "View in source") [Ⓣ][1] - -Examines each element in a `collection`, returning an array of all elements the `callback` returns truthy for. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. - -#### Aliases -*select* +### `_.prototype.chain()` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3974 "View in source") [Ⓣ][1] -#### Arguments -1. `collection` *(Array|Object|String)*: The collection to iterate over. -2. `[callback=identity]` *(Function)*: The function called per iteration. -3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. +Enables method chaining on the wrapper object. #### Returns -*(Array)*: Returns a new array of elements that passed the callback check. +*(Mixed)*: Returns the wrapper object. #### Example ```js -var evens = _.filter([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }); -// => [2, 4, 6] +_([1, 2, 3]).value(); +// => [1, 2, 3] ``` * * * @@ -701,26 +780,18 @@ var evens = _.filter([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }) -### `_.find(collection, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1991 "View in source") [Ⓣ][1] - -Examines each element in a `collection`, returning the first one the `callback` returns truthy for. The function returns as soon as it finds an acceptable element, and does not iterate over the entire `collection`. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. - -#### Aliases -*detect* +### `_.prototype.value()` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3991 "View in source") [Ⓣ][1] -#### Arguments -1. `collection` *(Array|Object|String)*: The collection to iterate over. -2. `callback` *(Function)*: The function called per iteration. -3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. +Extracts the wrapped value. #### Returns -*(Mixed)*: Returns the element that passed the callback check, else `undefined`. +*(Mixed)*: Returns the wrapped value. #### Example ```js -var even = _.find([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }); -// => 2 +_([1, 2, 3]).value(); +// => [1, 2, 3] ``` * * * @@ -728,27 +799,40 @@ var even = _.find([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }); + + + -### `_.first(array [, n])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2480 "View in source") [Ⓣ][1] +## `“Collections” Methods` -Gets the first element of the `array`. Pass `n` to return the first `n` elements of the `array`. + + +### `_.contains(collection, target)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1872 "View in source") [Ⓣ][1] + +Checks if a given `target` element is present in a `collection` using strict equality for comparisons, i.e. `===`. #### Aliases -*head, take* +*include* #### Arguments -1. `array` *(Array)*: The array to query. -2. `[n]` *(Number)*: The number of elements to return. +1. `collection` *(Array|Object|String)*: The collection to iterate over. +2. `target` *(Mixed)*: The value to check for. #### Returns -*(Mixed)*: Returns the first element or an array of the first `n` elements of `array`. +*(Boolean)*: Returns `true` if the `target` element is found, else `false`. #### Example ```js -_.first([5, 4, 3, 2, 1]); -// => 5 +_.contains([1, 2, 3], 3); +// => true + +_.contains({ 'name': 'moe', 'age': 40 }, 'moe'); +// => true + +_.contains('curly', 'ur'); +// => true ``` * * * @@ -758,25 +842,29 @@ _.first([5, 4, 3, 2, 1]); -### `_.flatten(array, shallow)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2504 "View in source") [Ⓣ][1] +### `_.countBy(collection, callback|property [, thisArg])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1908 "View in source") [Ⓣ][1] -Flattens a nested array *(the nesting can be to any depth)*. If `shallow` is truthy, `array` will only be flattened a single level. +Creates an object composed of keys returned from running each element of `collection` through a `callback`. The corresponding value of each key is the number of times the key was returned by `callback`. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. The `callback` argument may also be the name of a property to count by *(e.g. 'length')*. #### Arguments -1. `array` *(Array)*: The array to compact. -2. `shallow` *(Boolean)*: A flag to indicate only flattening a single level. +1. `collection` *(Array|Object|String)*: The collection to iterate over. +2. `callback|property` *(Function|String)*: The function called per iteration or property name to count by. +3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. #### Returns -*(Array)*: Returns a new flattened array. +*(Object)*: Returns the composed aggregate object. #### Example ```js -_.flatten([1, [2], [3, [[4]]]]); -// => [1, 2, 3, 4]; +_.countBy([4.3, 6.1, 6.4], function(num) { return Math.floor(num); }); +// => { '4': 1, '6': 2 } -_.flatten([1, [2], [3, [[4]]]], true); -// => [1, 2, 3, [[4]]]; +_.countBy([4.3, 6.1, 6.4], function(num) { return this.floor(num); }, Math); +// => { '4': 1, '6': 2 } + +_.countBy(['one', 'two', 'three'], 'length'); +// => { '3': 2, '5': 1 } ``` * * * @@ -786,29 +874,26 @@ _.flatten([1, [2], [3, [[4]]]], true); -### `_.forEach(collection, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2018 "View in source") [Ⓣ][1] +### `_.every(collection [, callback=identity, thisArg])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1929 "View in source") [Ⓣ][1] -Iterates over a `collection`, executing the `callback` for each element in the `collection`. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. Callbacks may exit iteration early by explicitly returning `false`. +Checks if the `callback` returns a truthy value for **all** elements of a `collection`. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. #### Aliases -*each* +*all* #### Arguments 1. `collection` *(Array|Object|String)*: The collection to iterate over. -2. `callback` *(Function)*: The function called per iteration. +2. `[callback=identity]` *(Function)*: The function called per iteration. 3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. #### Returns -*(Array, Object, String)*: Returns `collection`. +*(Boolean)*: Returns `true` if all elements pass the callback check, else `false`. #### Example ```js -_([1, 2, 3]).forEach(alert).join(','); -// => alerts each number and returns '1,2,3' - -_.forEach({ 'one': 1, 'two': 2, 'three': 3 }, alert); -// => alerts each number (order is not guaranteed) +_.every([true, 1, null, 'yes'], Boolean); +// => false ``` * * * @@ -818,33 +903,26 @@ _.forEach({ 'one': 1, 'two': 2, 'three': 3 }, alert); -### `_.forIn(object, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1182 "View in source") [Ⓣ][1] +### `_.filter(collection [, callback=identity, thisArg])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1949 "View in source") [Ⓣ][1] -Iterates over `object`'s own and inherited enumerable properties, executing the `callback` for each property. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, key, object)*. Callbacks may exit iteration early by explicitly returning `false`. +Examines each element in a `collection`, returning an array of all elements the `callback` returns truthy for. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. + +#### Aliases +*select* #### Arguments -1. `object` *(Object)*: The object to iterate over. -2. `callback` *(Function)*: The function called per iteration. +1. `collection` *(Array|Object|String)*: The collection to iterate over. +2. `[callback=identity]` *(Function)*: The function called per iteration. 3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. #### Returns -*(Object)*: Returns `object`. +*(Array)*: Returns a new array of elements that passed the callback check. #### Example ```js -function Dog(name) { - this.name = name; -} - -Dog.prototype.bark = function() { - alert('Woof, woof!'); -}; - -_.forIn(new Dog('Dagny'), function(value, key) { - alert(key); -}); -// => alerts 'name' and 'bark' (order is not guaranteed) +var evens = _.filter([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }); +// => [2, 4, 6] ``` * * * @@ -854,25 +932,26 @@ _.forIn(new Dog('Dagny'), function(value, key) { -### `_.forOwn(object, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1206 "View in source") [Ⓣ][1] +### `_.find(collection, callback [, thisArg])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1971 "View in source") [Ⓣ][1] -Iterates over `object`'s own enumerable properties, executing the `callback` for each property. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, key, object)*. Callbacks may exit iteration early by explicitly returning `false`. +Examines each element in a `collection`, returning the first one the `callback` returns truthy for. The function returns as soon as it finds an acceptable element, and does not iterate over the entire `collection`. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. + +#### Aliases +*detect* #### Arguments -1. `object` *(Object)*: The object to iterate over. +1. `collection` *(Array|Object|String)*: The collection to iterate over. 2. `callback` *(Function)*: The function called per iteration. 3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. #### Returns -*(Object)*: Returns `object`. +*(Mixed)*: Returns the element that passed the callback check, else `undefined`. #### Example ```js -_.forOwn({ '0': 'zero', '1': 'one', 'length': 2 }, function(num, key) { - alert(key); -}); -// => alerts '0', '1', and 'length' (order is not guaranteed) +var even = _.find([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }); +// => 2 ``` * * * @@ -882,24 +961,29 @@ _.forOwn({ '0': 'zero', '1': 'one', 'length': 2 }, function(num, key) { -### `_.functions(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1223 "View in source") [Ⓣ][1] +### `_.forEach(collection, callback [, thisArg])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1998 "View in source") [Ⓣ][1] -Creates a sorted array of all enumerable properties, own and inherited, of `object` that have function values. +Iterates over a `collection`, executing the `callback` for each element in the `collection`. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. Callbacks may exit iteration early by explicitly returning `false`. #### Aliases -*methods* +*each* #### Arguments -1. `object` *(Object)*: The object to inspect. +1. `collection` *(Array|Object|String)*: The collection to iterate over. +2. `callback` *(Function)*: The function called per iteration. +3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. #### Returns -*(Array)*: Returns a new array of property names that have function values. +*(Array, Object, String)*: Returns `collection`. #### Example ```js -_.functions(_); -// => ['all', 'any', 'bind', 'bindAll', 'clone', 'compact', 'compose', ...] +_([1, 2, 3]).forEach(alert).join(','); +// => alerts each number and returns '1,2,3' + +_.forEach({ 'one': 1, 'two': 2, 'three': 3 }, alert); +// => alerts each number (order is not guaranteed) ``` * * * @@ -910,7 +994,7 @@ _.functions(_); ### `_.groupBy(collection, callback|property [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2046 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2026 "View in source") [Ⓣ][1] Creates an object composed of keys returned from running each element of `collection` through a `callback`. The corresponding value of each key is an array of elements passed to `callback` that returned the key. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. The `callback` argument may also be the name of a property to count by *(e.g. 'length')*. @@ -941,22 +1025,26 @@ _.groupBy(['one', 'two', 'three'], 'length'); -### `_.has(object, property)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1246 "View in source") [Ⓣ][1] +### `_.invoke(collection, methodName [, arg1, arg2, ...])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2054 "View in source") [Ⓣ][1] -Checks if the specified object `property` exists and is a direct property, instead of an inherited property. +Invokes the method named by `methodName` on each element in the `collection`, returning an array of the results of each invoked method. Additional arguments will be passed to each invoked method. If `methodName` is a function it will be invoked for, and `this` bound to, each element in the `collection`. #### Arguments -1. `object` *(Object)*: The object to check. -2. `property` *(String)*: The property to check for. +1. `collection` *(Array|Object|String)*: The collection to iterate over. +2. `methodName` *(Function|String)*: The name of the method to invoke or the function invoked per iteration. +3. `[arg1, arg2, ...]` *(Mixed)*: Arguments to invoke the method with. #### Returns -*(Boolean)*: Returns `true` if key is a direct property, else `false`. +*(Array)*: Returns a new array of the results of each invoked method. #### Example ```js -_.has({ 'a': 1, 'b': 2, 'c': 3 }, 'b'); -// => true +_.invoke([[5, 1, 7], [3, 2, 1]], 'sort'); +// => [[1, 5, 7], [1, 2, 3]] + +_.invoke([123, 456], String.prototype.split, ''); +// => [['1', '2', '3'], ['4', '5', '6']] ``` * * * @@ -966,22 +1054,29 @@ _.has({ 'a': 1, 'b': 2, 'c': 3 }, 'b'); -### `_.identity(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3546 "View in source") [Ⓣ][1] +### `_.map(collection [, callback=identity, thisArg])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2089 "View in source") [Ⓣ][1] -This function returns the first argument passed to it. Note: It is used throughout Lo-Dash as a default callback. +Creates an array of values by running each element in the `collection` through a `callback`. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. + +#### Aliases +*collect* #### Arguments -1. `value` *(Mixed)*: Any value. +1. `collection` *(Array|Object|String)*: The collection to iterate over. +2. `[callback=identity]` *(Function)*: The function called per iteration. +3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. #### Returns -*(Mixed)*: Returns `value`. +*(Array)*: Returns a new array of the results of each `callback` execution. #### Example ```js -var moe = { 'name': 'moe' }; -moe === _.identity(moe); -// => true +_.map([1, 2, 3], function(num) { return num * 3; }); +// => [3, 6, 9] + +_.map({ 'one': 1, 'two': 2, 'three': 3 }, function(num) { return num * 3; }); +// => [3, 6, 9] (order is not guaranteed) ``` * * * @@ -991,29 +1086,29 @@ moe === _.identity(moe); -### `_.indexOf(array, value [, fromIndex=0])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2547 "View in source") [Ⓣ][1] +### `_.max(collection [, callback, thisArg])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2115 "View in source") [Ⓣ][1] -Gets the index at which the first occurrence of `value` is found using strict equality for comparisons, i.e. `===`. If the `array` is already sorted, passing `true` for `isSorted` will run a faster binary search. +Retrieves the maximum value of an `array`. If `callback` is passed, it will be executed for each value in the `array` to generate the criterion by which the value is ranked. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index, collection)*. #### Arguments -1. `array` *(Array)*: The array to search. -2. `value` *(Mixed)*: The value to search for. -3. `[fromIndex=0]` *(Boolean|Number)*: The index to start searching from or `true` to perform a binary search on a sorted `array`. +1. `collection` *(Array)*: The collection to iterate over. +2. `[callback]` *(Function)*: The function called per iteration. +3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. #### Returns -*(Number)*: Returns the index of the matched value or `-1`. +*(Mixed)*: Returns the maximum value. #### Example ```js -_.indexOf([1, 2, 3, 1, 2, 3], 2); -// => 1 - -_.indexOf([1, 2, 3, 1, 2, 3], 2, 3); -// => 4 +var stooges = [ + { 'name': 'moe', 'age': 40 }, + { 'name': 'larry', 'age': 50 }, + { 'name': 'curly', 'age': 60 } +]; -_.indexOf([1, 1, 2, 2, 3, 3], 2, true); -// => 2 +_.max(stooges, function(stooge) { return stooge.age; }); +// => { 'name': 'curly', 'age': 60 }; ``` * * * @@ -1023,22 +1118,23 @@ _.indexOf([1, 1, 2, 2, 3, 3], 2, true); -### `_.initial(array [, n])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2582 "View in source") [Ⓣ][1] +### `_.min(collection [, callback, thisArg])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2158 "View in source") [Ⓣ][1] -Gets all but the last element of `array`. Pass `n` to exclude the last `n` elements from the result. +Retrieves the minimum value of an `array`. If `callback` is passed, it will be executed for each value in the `array` to generate the criterion by which the value is ranked. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index, collection)*. #### Arguments -1. `array` *(Array)*: The array to query. -2. `[n]` *(Number)*: The number of elements to return. +1. `collection` *(Array)*: The collection to iterate over. +2. `[callback]` *(Function)*: The function called per iteration. +3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. #### Returns -*(Array)*: Returns all but the last element or `n` elements of `array`. +*(Mixed)*: Returns the minimum value. #### Example ```js -_.initial([3, 2, 1]); -// => [3, 2] +_.min([10, 5, 100, 2, 1000]); +// => 2 ``` * * * @@ -1048,21 +1144,28 @@ _.initial([3, 2, 1]); -### `_.intersection([array1, array2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2603 "View in source") [Ⓣ][1] +### `_.pluck(collection, property)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2204 "View in source") [Ⓣ][1] -Computes the intersection of all the passed-in arrays using strict equality for comparisons, i.e. `===`. +Retrieves the value of a specified property from all elements in the `collection`. #### Arguments -1. `[array1, array2, ...]` *(Array)*: Arrays to process. +1. `collection` *(Array|Object|String)*: The collection to iterate over. +2. `property` *(String)*: The property to pluck. #### Returns -*(Array)*: Returns a new array of unique elements, in order, that are present in **all** of the arrays. +*(Array)*: Returns a new array of property values. #### Example ```js -_.intersection([1, 2, 3], [101, 2, 1, 10], [2, 1]); -// => [1, 2] +var stooges = [ + { 'name': 'moe', 'age': 40 }, + { 'name': 'larry', 'age': 50 }, + { 'name': 'curly', 'age': 60 } +]; + +_.pluck(stooges, 'name'); +// => ['moe', 'larry', 'curly'] ``` * * * @@ -1072,21 +1175,27 @@ _.intersection([1, 2, 3], [101, 2, 1, 10], [2, 1]); -### `_.invert(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L814 "View in source") [Ⓣ][1] +### `_.reduce(collection, callback [, accumulator, thisArg])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2232 "View in source") [Ⓣ][1] -Creates an object composed of the inverted keys and values of the given `object`. +Boils down a `collection` to a single value. The initial state of the reduction is `accumulator` and each successive step of it should be returned by the `callback`. The `callback` is bound to `thisArg` and invoked with `4` arguments; for arrays they are *(accumulator, value, index|key, collection)*. + +#### Aliases +*foldl, inject* #### Arguments -1. `object` *(Object)*: The object to invert. +1. `collection` *(Array|Object|String)*: The collection to iterate over. +2. `callback` *(Function)*: The function called per iteration. +3. `[accumulator]` *(Mixed)*: Initial value of the accumulator. +4. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. #### Returns -*(Object)*: Returns the created inverted object. +*(Mixed)*: Returns the accumulated value. #### Example ```js -_.invert({ 'first': 'Moe', 'second': 'Larry', 'third': 'Curly' }); -// => { 'Moe': 'first', 'Larry': 'second', 'Curly': 'third' } (order is not guaranteed) +var sum = _.reduce([1, 2, 3], function(memo, num) { return memo + num; }); +// => 6 ``` * * * @@ -1096,26 +1205,28 @@ _.invert({ 'first': 'Moe', 'second': 'Larry', 'third': 'Curly' }); -### `_.invoke(collection, methodName [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2074 "View in source") [Ⓣ][1] +### `_.reduceRight(collection, callback [, accumulator, thisArg])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2269 "View in source") [Ⓣ][1] -Invokes the method named by `methodName` on each element in the `collection`, returning an array of the results of each invoked method. Additional arguments will be passed to each invoked method. If `methodName` is a function it will be invoked for, and `this` bound to, each element in the `collection`. +The right-associative version of `_.reduce`. + +#### Aliases +*foldr* #### Arguments 1. `collection` *(Array|Object|String)*: The collection to iterate over. -2. `methodName` *(Function|String)*: The name of the method to invoke or the function invoked per iteration. -3. `[arg1, arg2, ...]` *(Mixed)*: Arguments to invoke the method with. +2. `callback` *(Function)*: The function called per iteration. +3. `[accumulator]` *(Mixed)*: Initial value of the accumulator. +4. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. #### Returns -*(Array)*: Returns a new array of the results of each invoked method. +*(Mixed)*: Returns the accumulated value. #### Example ```js -_.invoke([[5, 1, 7], [3, 2, 1]], 'sort'); -// => [[1, 5, 7], [1, 2, 3]] - -_.invoke([123, 456], String.prototype.split, ''); -// => [['1', '2', '3'], ['4', '5', '6']] +var list = [[0, 1], [2, 3], [4, 5]]; +var flat = _.reduceRight(list, function(a, b) { return a.concat(b); }, []); +// => [4, 5, 2, 3, 0, 1] ``` * * * @@ -1125,24 +1236,23 @@ _.invoke([123, 456], String.prototype.split, ''); -### `_.isArguments(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L836 "View in source") [Ⓣ][1] +### `_.reject(collection [, callback=identity, thisArg])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2306 "View in source") [Ⓣ][1] -Checks if `value` is an `arguments` object. +The opposite of `_.filter`, this method returns the values of a `collection` that `callback` does **not** return truthy for. #### Arguments -1. `value` *(Mixed)*: The value to check. +1. `collection` *(Array|Object|String)*: The collection to iterate over. +2. `[callback=identity]` *(Function)*: The function called per iteration. +3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. #### Returns -*(Boolean)*: Returns `true` if the `value` is an `arguments` object, else `false`. +*(Array)*: Returns a new array of elements that did **not** pass the callback check. #### Example ```js -(function() { return _.isArguments(arguments); })(1, 2, 3); -// => true - -_.isArguments([1, 2, 3]); -// => false +var odds = _.reject([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }); +// => [1, 3, 5] ``` * * * @@ -1152,24 +1262,21 @@ _.isArguments([1, 2, 3]); -### `_.isArray(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L862 "View in source") [Ⓣ][1] +### `_.shuffle(collection)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2324 "View in source") [Ⓣ][1] -Checks if `value` is an array. +Creates an array of shuffled `array` values, using a version of the Fisher-Yates shuffle. See http://en.wikipedia.org/wiki/Fisher-Yates_shuffle. #### Arguments -1. `value` *(Mixed)*: The value to check. +1. `collection` *(Array)*: The collection to shuffle. #### Returns -*(Boolean)*: Returns `true` if the `value` is an array, else `false`. +*(Array)*: Returns a new shuffled collection. #### Example ```js -(function() { return _.isArray(arguments); })(); -// => false - -_.isArray([1, 2, 3]); -// => true +_.shuffle([1, 2, 3, 4, 5, 6]); +// => [4, 1, 6, 3, 5, 2] ``` * * * @@ -1179,45 +1286,27 @@ _.isArray([1, 2, 3]); -### `_.isBoolean(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1263 "View in source") [Ⓣ][1] +### `_.size(collection)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2356 "View in source") [Ⓣ][1] -Checks if `value` is a boolean *(`true` or `false`)* value. +Gets the size of the `collection` by returning `collection.length` for arrays and array-like objects or the number of own enumerable properties for objects. #### Arguments -1. `value` *(Mixed)*: The value to check. +1. `collection` *(Array|Object|String)*: The collection to inspect. #### Returns -*(Boolean)*: Returns `true` if the `value` is a boolean value, else `false`. +*(Number)*: Returns `collection.length` or number of own enumerable properties. #### Example ```js -_.isBoolean(null); -// => false -``` - -* * * - - - - - - -### `_.isDate(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1280 "View in source") [Ⓣ][1] - -Checks if `value` is a date. - -#### Arguments -1. `value` *(Mixed)*: The value to check. +_.size([1, 2]); +// => 2 -#### Returns -*(Boolean)*: Returns `true` if the `value` is a date, else `false`. +_.size({ 'one': 1, 'two': 2, 'three': 3 }); +// => 3 -#### Example -```js -_.isDate(new Date); -// => true +_.size('curly'); +// => 5 ``` * * * @@ -1227,20 +1316,25 @@ _.isDate(new Date); -### `_.isElement(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1297 "View in source") [Ⓣ][1] +### `_.some(collection [, callback=identity, thisArg])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2381 "View in source") [Ⓣ][1] -Checks if `value` is a DOM element. +Checks if the `callback` returns a truthy value for **any** element of a `collection`. The function returns as soon as it finds passing value, and does not iterate over the entire `collection`. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. + +#### Aliases +*any* #### Arguments -1. `value` *(Mixed)*: The value to check. +1. `collection` *(Array|Object|String)*: The collection to iterate over. +2. `[callback=identity]` *(Function)*: The function called per iteration. +3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. #### Returns -*(Boolean)*: Returns `true` if the `value` is a DOM element, else `false`. +*(Boolean)*: Returns `true` if any element passes the callback check, else `false`. #### Example ```js -_.isElement(document.body); +_.some([null, 0, 'yes', false]); // => true ``` @@ -1251,27 +1345,29 @@ _.isElement(document.body); -### `_.isEmpty(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1322 "View in source") [Ⓣ][1] +### `_.sortBy(collection, callback|property [, thisArg])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2411 "View in source") [Ⓣ][1] -Checks if `value` is empty. Arrays, strings, or `arguments` objects with a length of `0` and objects with no own enumerable properties are considered "empty". +Creates an array, stable sorted in ascending order by the results of running each element of `collection` through a `callback`. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. The `callback` argument may also be the name of a property to sort by *(e.g. 'length')*. #### Arguments -1. `value` *(Array|Object|String)*: The value to inspect. +1. `collection` *(Array|Object|String)*: The collection to iterate over. +2. `callback|property` *(Function|String)*: The function called per iteration or property name to sort by. +3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. #### Returns -*(Boolean)*: Returns `true` if the `value` is empty, else `false`. +*(Array)*: Returns a new array of sorted elements. #### Example ```js -_.isEmpty([1, 2, 3]); -// => false +_.sortBy([1, 2, 3], function(num) { return Math.sin(num); }); +// => [3, 1, 2] -_.isEmpty({}); -// => true +_.sortBy([1, 2, 3], function(num) { return this.sin(num); }, Math); +// => [3, 1, 2] -_.isEmpty(''); -// => true +_.sortBy(['larry', 'brendan', 'moe'], 'length'); +// => ['moe', 'larry', 'brendan'] ``` * * * @@ -1281,28 +1377,21 @@ _.isEmpty(''); -### `_.isEqual(a, b)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1361 "View in source") [Ⓣ][1] +### `_.toArray(collection)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2447 "View in source") [Ⓣ][1] -Performs a deep comparison between two values to determine if they are equivalent to each other. +Converts the `collection`, to an array. #### Arguments -1. `a` *(Mixed)*: The value to compare. -2. `b` *(Mixed)*: The other value to compare. +1. `collection` *(Array|Object|String)*: The collection to convert. #### Returns -*(Boolean)*: Returns `true` if the values are equvalent, else `false`. +*(Array)*: Returns the new converted array. #### Example ```js -var moe = { 'name': 'moe', 'luckyNumbers': [13, 27, 34] }; -var clone = { 'name': 'moe', 'luckyNumbers': [13, 27, 34] }; - -moe == clone; -// => false - -_.isEqual(moe, clone); -// => true +(function() { return _.toArray(arguments).slice(1); })(1, 2, 3, 4); +// => [2, 3, 4] ``` * * * @@ -1312,27 +1401,28 @@ _.isEqual(moe, clone); -### `_.isFinite(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1518 "View in source") [Ⓣ][1] +### `_.where(collection, properties)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2481 "View in source") [Ⓣ][1] -Checks if `value` is a finite number. Note: This is not the same as native `isFinite`, which will return true for booleans and other values. See http://es5.github.com/#x15.1.2.5. +Examines each element in a `collection`, returning an array of all elements that contain the given `properties`. #### Arguments -1. `value` *(Mixed)*: The value to check. +1. `collection` *(Array|Object|String)*: The collection to iterate over. +2. `properties` *(Object)*: The object of properties/values to filter by. #### Returns -*(Boolean)*: Returns `true` if the `value` is a finite number, else `false`. +*(Array)*: Returns a new array of elements that contain the given `properties`. #### Example ```js -_.isFinite(-101); -// => true - -_.isFinite('10'); -// => false +var stooges = [ + { 'name': 'moe', 'age': 40 }, + { 'name': 'larry', 'age': 50 }, + { 'name': 'curly', 'age': 60 } +]; -_.isFinite(Infinity); -// => false +_.where(stooges, { 'age': 40 }); +// => [{ 'name': 'moe', 'age': 40 }] ``` * * * @@ -1340,23 +1430,34 @@ _.isFinite(Infinity); + + + -### `_.isFunction(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L879 "View in source") [Ⓣ][1] +## `“Functions” Methods` -Checks if `value` is a function. + + +### `_.after(n, func)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3110 "View in source") [Ⓣ][1] + +Creates a function that is restricted to executing only after it is called `n` times. #### Arguments -1. `value` *(Mixed)*: The value to check. +1. `n` *(Number)*: The number of times the function must be called before it is executed. +2. `func` *(Function)*: The function to restrict. #### Returns -*(Boolean)*: Returns `true` if the `value` is a function, else `false`. +*(Function)*: Returns the new restricted function. #### Example ```js -_.isFunction(_); -// => true +var renderNotes = _.after(notes.length, render); +_.forEach(notes, function(note) { + note.asyncSave({ 'success': renderNotes }); +}); +// `renderNotes` is run once, after all notes have saved ``` * * * @@ -1366,30 +1467,28 @@ _.isFunction(_); -### `_.isNaN(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1576 "View in source") [Ⓣ][1] +### `_.bind(func [, thisArg, arg1, arg2, ...])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3143 "View in source") [Ⓣ][1] -Checks if `value` is `NaN`. Note: This is not the same as native `isNaN`, which will return true for `undefined` and other values. See http://es5.github.com/#x15.1.2.4. +Creates a function that, when called, invokes `func` with the `this` binding of `thisArg` and prepends any additional `bind` arguments to those passed to the bound function. #### Arguments -1. `value` *(Mixed)*: The value to check. +1. `func` *(Function)*: The function to bind. +2. `[thisArg]` *(Mixed)*: The `this` binding of `func`. +3. `[arg1, arg2, ...]` *(Mixed)*: Arguments to be partially applied. #### Returns -*(Boolean)*: Returns `true` if the `value` is `NaN`, else `false`. +*(Function)*: Returns the new bound function. #### Example ```js -_.isNaN(NaN); -// => true - -_.isNaN(new Number(NaN)); -// => true - -isNaN(undefined); -// => true +var func = function(greeting) { + return greeting + ' ' + this.name; +}; -_.isNaN(undefined); -// => false +func = _.bind(func, { 'name': 'moe' }, 'hi'); +func(); +// => 'hi moe' ``` * * * @@ -1399,24 +1498,28 @@ _.isNaN(undefined); -### `_.isNull(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1599 "View in source") [Ⓣ][1] +### `_.bindAll(object [, methodName1, methodName2, ...])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3173 "View in source") [Ⓣ][1] -Checks if `value` is `null`. +Binds methods on `object` to `object`, overwriting the existing method. If no method names are provided, all the function properties of `object` will be bound. #### Arguments -1. `value` *(Mixed)*: The value to check. +1. `object` *(Object)*: The object to bind and assign the bound methods to. +2. `[methodName1, methodName2, ...]` *(String)*: Method names on the object to bind. #### Returns -*(Boolean)*: Returns `true` if the `value` is `null`, else `false`. +*(Object)*: Returns `object`. #### Example ```js -_.isNull(null); -// => true +var buttonView = { + 'label': 'lodash', + 'onClick': function() { alert('clicked: ' + this.label); } +}; -_.isNull(undefined); -// => false +_.bindAll(buttonView); +jQuery('#lodash_button').on('click', buttonView.onClick); +// => When the button is clicked, `this.label` will have the correct value ``` * * * @@ -1426,21 +1529,24 @@ _.isNull(undefined); -### `_.isNumber(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1616 "View in source") [Ⓣ][1] +### `_.compose([func1, func2, ...])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3209 "View in source") [Ⓣ][1] -Checks if `value` is a number. +Creates a function that is the composition of the passed functions, where each function consumes the return value of the function that follows. In math terms, composing the functions `f()`, `g()`, and `h()` produces `f(g(h()))`. #### Arguments -1. `value` *(Mixed)*: The value to check. +1. `[func1, func2, ...]` *(Function)*: Functions to compose. #### Returns -*(Boolean)*: Returns `true` if the `value` is a number, else `false`. +*(Function)*: Returns the new composed function. #### Example ```js -_.isNumber(8.4 * 5); -// => true +var greet = function(name) { return 'hi: ' + name; }; +var exclaim = function(statement) { return statement + '!'; }; +var welcome = _.compose(exclaim, greet); +welcome('moe'); +// => 'hi: moe!' ``` * * * @@ -1450,27 +1556,23 @@ _.isNumber(8.4 * 5); -### `_.isObject(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1542 "View in source") [Ⓣ][1] +### `_.debounce(func, wait, immediate)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3242 "View in source") [Ⓣ][1] -Checks if `value` is the language type of Object. *(e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)* +Creates a function that will delay the execution of `func` until after `wait` milliseconds have elapsed since the last time it was invoked. Pass `true` for `immediate` to cause debounce to invoke `func` on the leading, instead of the trailing, edge of the `wait` timeout. Subsequent calls to the debounced function will return the result of the last `func` call. #### Arguments -1. `value` *(Mixed)*: The value to check. +1. `func` *(Function)*: The function to debounce. +2. `wait` *(Number)*: The number of milliseconds to delay. +3. `immediate` *(Boolean)*: A flag to indicate execution is on the leading edge of the timeout. #### Returns -*(Boolean)*: Returns `true` if the `value` is an object, else `false`. +*(Function)*: Returns the new debounced function. #### Example ```js -_.isObject({}); -// => true - -_.isObject([1, 2, 3]); -// => true - -_.isObject(1); -// => false +var lazyLayout = _.debounce(calculateLayout, 300); +jQuery(window).on('resize', lazyLayout); ``` * * * @@ -1480,32 +1582,22 @@ _.isObject(1); -### `_.isPlainObject(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L913 "View in source") [Ⓣ][1] +### `_.defer(func [, arg1, arg2, ...])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3307 "View in source") [Ⓣ][1] -Checks if a given `value` is an object created by the `Object` constructor. +Defers executing the `func` function until the current call stack has cleared. Additional arguments will be passed to `func` when it is invoked. #### Arguments -1. `value` *(Mixed)*: The value to check. +1. `func` *(Function)*: The function to defer. +2. `[arg1, arg2, ...]` *(Mixed)*: Arguments to invoke the function with. #### Returns -*(Boolean)*: Returns `true` if `value` is a plain object, else `false`. +*(Number)*: Returns the `setTimeout` timeout id. #### Example ```js -function Stooge(name, age) { - this.name = name; - this.age = age; -} - -_.isPlainObject(new Stooge('moe', 40)); -// false - -_.isPlainObject([1, 2, 3]); -// false - -_.isPlainObject({ 'name': 'moe', 'age': 40 }); -// => true +_.defer(function() { alert('deferred'); }); +// returns from the function before `alert` is called ``` * * * @@ -1515,21 +1607,24 @@ _.isPlainObject({ 'name': 'moe', 'age': 40 }); -### `_.isRegExp(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1633 "View in source") [Ⓣ][1] +### `_.delay(func, wait [, arg1, arg2, ...])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3287 "View in source") [Ⓣ][1] -Checks if `value` is a regular expression. +Executes the `func` function after `wait` milliseconds. Additional arguments will be passed to `func` when it is invoked. #### Arguments -1. `value` *(Mixed)*: The value to check. +1. `func` *(Function)*: The function to delay. +2. `wait` *(Number)*: The number of milliseconds to delay execution. +3. `[arg1, arg2, ...]` *(Mixed)*: Arguments to invoke the function with. #### Returns -*(Boolean)*: Returns `true` if the `value` is a regular expression, else `false`. +*(Number)*: Returns the `setTimeout` timeout id. #### Example ```js -_.isRegExp(/moe/); -// => true +var log = _.bind(console.log, console); +_.delay(log, 1000, 'logged later'); +// => 'logged later' (Appears after one second.) ``` * * * @@ -1539,21 +1634,38 @@ _.isRegExp(/moe/); -### `_.isString(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1650 "View in source") [Ⓣ][1] +### `_.lateBind(object, methodName [, arg1, arg2, ...])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3345 "View in source") [Ⓣ][1] -Checks if `value` is a string. +Creates a function that, when called, invokes `object[methodName]` and prepends any additional `lateBind` arguments to those passed to the bound function. This method differs from `_.bind` by allowing bound functions to reference methods that will be redefined or don't yet exist. #### Arguments -1. `value` *(Mixed)*: The value to check. +1. `object` *(Object)*: The object the method belongs to. +2. `methodName` *(String)*: The method name. +3. `[arg1, arg2, ...]` *(Mixed)*: Arguments to be partially applied. #### Returns -*(Boolean)*: Returns `true` if the `value` is a string, else `false`. +*(Function)*: Returns the new bound function. #### Example ```js -_.isString('moe'); -// => true +var object = { + 'name': 'moe', + 'greet': function(greeting) { + return greeting + ' ' + this.name; + } +}; + +var func = _.lateBind(object, 'greet', 'hi'); +func(); +// => 'hi moe' + +object.greet = function(greeting) { + return greeting + ', ' + this.name + '!'; +}; + +func(); +// => 'hi, moe!' ``` * * * @@ -1563,21 +1675,23 @@ _.isString('moe'); -### `_.isUndefined(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1668 "View in source") [Ⓣ][1] +### `_.memoize(func [, resolver])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3367 "View in source") [Ⓣ][1] -Checks if `value` is `undefined`. +Creates a function that memoizes the result of `func`. If `resolver` is passed, it will be used to determine the cache key for storing the result based on the arguments passed to the memoized function. By default, the first argument passed to the memoized function is used as the cache key. #### Arguments -1. `value` *(Mixed)*: The value to check. +1. `func` *(Function)*: The function to have its output memoized. +2. `[resolver]` *(Function)*: A function used to resolve the cache key. #### Returns -*(Boolean)*: Returns `true` if the `value` is `undefined`, else `false`. +*(Function)*: Returns the new memoizing function. #### Example ```js -_.isUndefined(void 0); -// => true +var fibonacci = _.memoize(function(n) { + return n < 2 ? n : fibonacci(n - 1) + fibonacci(n - 2); +}); ``` * * * @@ -1587,21 +1701,23 @@ _.isUndefined(void 0); -### `_.keys(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1685 "View in source") [Ⓣ][1] +### `_.once(func)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3393 "View in source") [Ⓣ][1] -Creates an array composed of the own enumerable property names of `object`. +Creates a function that is restricted to one execution. Repeat calls to the function will return the value of the first call. #### Arguments -1. `object` *(Object)*: The object to inspect. +1. `func` *(Function)*: The function to restrict. #### Returns -*(Array)*: Returns a new array of property names. +*(Function)*: Returns the new restricted function. #### Example ```js -_.keys({ 'one': 1, 'two': 2, 'three': 3 }); -// => ['one', 'two', 'three'] (order is not guaranteed) +var initialize = _.once(createApplication); +initialize(); +initialize(); +// Application is only created once. ``` * * * @@ -1611,22 +1727,24 @@ _.keys({ 'one': 1, 'two': 2, 'three': 3 }); -### `_.last(array [, n])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2642 "View in source") [Ⓣ][1] +### `_.partial(func [, arg1, arg2, ...])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3428 "View in source") [Ⓣ][1] -Gets the last element of the `array`. Pass `n` to return the last `n` elements of the `array`. +Creates a function that, when called, invokes `func` with any additional `partial` arguments prepended to those passed to the new function. This method is similar to `bind`, except it does **not** alter the `this` binding. #### Arguments -1. `array` *(Array)*: The array to query. -2. `[n]` *(Number)*: The number of elements to return. +1. `func` *(Function)*: The function to partially apply arguments to. +2. `[arg1, arg2, ...]` *(Mixed)*: Arguments to be partially applied. #### Returns -*(Mixed)*: Returns the last element or an array of the last `n` elements of `array`. +*(Function)*: Returns the new partially applied function. #### Example ```js -_.last([3, 2, 1]); -// => 1 +var greet = function(greeting, name) { return greeting + ': ' + name; }; +var hi = _.partial(greet, 'hi'); +hi('moe'); +// => 'hi: moe' ``` * * * @@ -1636,26 +1754,22 @@ _.last([3, 2, 1]); -### `_.lastIndexOf(array, value [, fromIndex=array.length-1])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2668 "View in source") [Ⓣ][1] +### `_.throttle(func, wait)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3450 "View in source") [Ⓣ][1] -Gets the index at which the last occurrence of `value` is found using strict equality for comparisons, i.e. `===`. +Creates a function that, when executed, will only call the `func` function at most once per every `wait` milliseconds. If the throttled function is invoked more than once during the `wait` timeout, `func` will also be called on the trailing edge of the timeout. Subsequent calls to the throttled function will return the result of the last `func` call. #### Arguments -1. `array` *(Array)*: The array to search. -2. `value` *(Mixed)*: The value to search for. -3. `[fromIndex=array.length-1]` *(Number)*: The index to start searching from. +1. `func` *(Function)*: The function to throttle. +2. `wait` *(Number)*: The number of milliseconds to throttle executions to. #### Returns -*(Number)*: Returns the index of the matched value or `-1`. +*(Function)*: Returns the new throttled function. #### Example ```js -_.lastIndexOf([1, 2, 3, 1, 2, 3], 2); -// => 4 - -_.lastIndexOf([1, 2, 3, 1, 2, 3], 2, 3); -// => 1 +var throttled = _.throttle(updatePosition, 100); +jQuery(window).on('scroll', throttled); ``` * * * @@ -1665,38 +1779,26 @@ _.lastIndexOf([1, 2, 3, 1, 2, 3], 2, 3); -### `_.lateBind(object, methodName [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3344 "View in source") [Ⓣ][1] +### `_.wrap(value, wrapper)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3502 "View in source") [Ⓣ][1] -Creates a function that, when called, invokes `object[methodName]` and prepends any additional `lateBind` arguments to those passed to the bound function. This method differs from `_.bind` by allowing bound functions to reference methods that will be redefined or don't yet exist. +Creates a function that passes `value` to the `wrapper` function as its first argument. Additional arguments passed to the new function are appended to those passed to the `wrapper` function. #### Arguments -1. `object` *(Object)*: The object the method belongs to. -2. `methodName` *(String)*: The method name. -3. `[arg1, arg2, ...]` *(Mixed)*: Arguments to be partially applied. +1. `value` *(Mixed)*: The value to wrap. +2. `wrapper` *(Function)*: The wrapper function. #### Returns -*(Function)*: Returns the new bound function. +*(Function)*: Returns the new function. #### Example ```js -var object = { - 'name': 'moe', - 'greet': function(greeting) { - return greeting + ' ' + this.name; - } -}; - -var func = _.lateBind(object, 'greet', 'hi'); -func(); -// => 'hi moe' - -object.greet = function(greeting) { - return greeting + ', ' + this.name + '!'; -}; - -func(); -// => 'hi, moe!' +var hello = function(name) { return 'hello: ' + name; }; +hello = _.wrap(hello, function(func) { + return 'before, ' + func('moe') + ', after'; +}); +hello(); +// => 'before, hello: moe, after' ``` * * * @@ -1704,52 +1806,26 @@ func(); - - -### `_.map(collection [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2109 "View in source") [Ⓣ][1] - -Creates an array of values by running each element in the `collection` through a `callback`. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. - -#### Aliases -*collect* - -#### Arguments -1. `collection` *(Array|Object|String)*: The collection to iterate over. -2. `[callback=identity]` *(Function)*: The function called per iteration. -3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. - -#### Returns -*(Array)*: Returns a new array of the results of each `callback` execution. - -#### Example -```js -_.map([1, 2, 3], function(num) { return num * 3; }); -// => [3, 6, 9] - -_.map({ 'one': 1, 'two': 2, 'three': 3 }, function(num) { return num * 3; }); -// => [3, 6, 9] (order is not guaranteed) -``` + -* * * - + +## `“Objects” Methods` -### `_.max(array [, callback, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2705 "View in source") [Ⓣ][1] +### `_.clone(value, deep)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1029 "View in source") [Ⓣ][1] -Retrieves the maximum value of an `array`. If `callback` is passed, it will be executed for each value in the `array` to generate the criterion by which the value is ranked. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index, array)*. +Creates a clone of `value`. If `deep` is `true`, all nested objects will also be cloned otherwise they will be assigned by reference. Functions, DOM nodes, `arguments` objects, and objects created by constructors other than `Object` are **not** cloned. #### Arguments -1. `array` *(Array)*: The array to iterate over. -2. `[callback]` *(Function)*: The function called per iteration. -3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. +1. `value` *(Mixed)*: The value to clone. +2. `deep` *(Boolean)*: A flag to indicate a deep clone. #### Returns -*(Mixed)*: Returns the maximum value. +*(Mixed)*: Returns the cloned `value`. #### Example ```js @@ -1759,8 +1835,16 @@ var stooges = [ { 'name': 'curly', 'age': 60 } ]; -_.max(stooges, function(stooge) { return stooge.age; }); -// => { 'name': 'curly', 'age': 60 }; +_.clone({ 'name': 'moe' }); +// => { 'name': 'moe' } + +var shallow = _.clone(stooges); +shallow[0] === stooges[0]; +// => true + +var deep = _.clone(stooges, true); +shallow[0] === stooges[0]; +// => false ``` * * * @@ -1770,23 +1854,23 @@ _.max(stooges, function(stooge) { return stooge.age; }); -### `_.memoize(func [, resolver])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3366 "View in source") [Ⓣ][1] +### `_.defaults(object [, default1, default2, ...])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1112 "View in source") [Ⓣ][1] -Creates a function that memoizes the result of `func`. If `resolver` is passed, it will be used to determine the cache key for storing the result based on the arguments passed to the memoized function. By default, the first argument passed to the memoized function is used as the cache key. +Assigns enumerable properties of the default object(s) to the `destination` object for all `destination` properties that resolve to `null`/`undefined`. Once a property is set, additional defaults of the same property will be ignored. #### Arguments -1. `func` *(Function)*: The function to have its output memoized. -2. `[resolver]` *(Function)*: A function used to resolve the cache key. +1. `object` *(Object)*: The destination object. +2. `[default1, default2, ...]` *(Object)*: The default objects. #### Returns -*(Function)*: Returns the new memoizing function. +*(Object)*: Returns the destination object. #### Example ```js -var fibonacci = _.memoize(function(n) { - return n < 2 ? n : fibonacci(n - 1) + fibonacci(n - 2); -}); +var iceCream = { 'flavor': 'chocolate' }; +_.defaults(iceCream, { 'flavor': 'vanilla', 'sprinkles': 'rainbow' }); +// => { 'flavor': 'chocolate', 'sprinkles': 'rainbow' } ``` * * * @@ -1796,10 +1880,10 @@ var fibonacci = _.memoize(function(n) { -### `_.merge(object [, source1, source2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1728 "View in source") [Ⓣ][1] +### `_.extend(object [, source1, source2, ...])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1132 "View in source") [Ⓣ][1] -Merges enumerable properties of the source object(s) into the `destination` object. Subsequent sources will overwrite propery assignments of previous sources. +Assigns enumerable properties of the source object(s) to the `destination` object. Subsequent sources will overwrite propery assignments of previous sources. #### Arguments 1. `object` *(Object)*: The destination object. @@ -1810,18 +1894,8 @@ Merges enumerable properties of the source object(s) into the `destination` obje #### Example ```js -var stooges = [ - { 'name': 'moe' }, - { 'name': 'larry' } -]; - -var ages = [ - { 'age': 40 }, - { 'age': 50 } -]; - -_.merge(stooges, ages); -// => [{ 'name': 'moe', 'age': 40 }, { 'name': 'larry', 'age': 50 }] +_.extend({ 'name': 'moe' }, { 'age': 40 }); +// => { 'name': 'moe', 'age': 40 } ``` * * * @@ -1831,23 +1905,33 @@ _.merge(stooges, ages); -### `_.min(array [, callback, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2741 "View in source") [Ⓣ][1] +### `_.forIn(object, callback [, thisArg])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1162 "View in source") [Ⓣ][1] -Retrieves the minimum value of an `array`. If `callback` is passed, it will be executed for each value in the `array` to generate the criterion by which the value is ranked. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index, array)*. +Iterates over `object`'s own and inherited enumerable properties, executing the `callback` for each property. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, key, object)*. Callbacks may exit iteration early by explicitly returning `false`. #### Arguments -1. `array` *(Array)*: The array to iterate over. -2. `[callback]` *(Function)*: The function called per iteration. +1. `object` *(Object)*: The object to iterate over. +2. `callback` *(Function)*: The function called per iteration. 3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. #### Returns -*(Mixed)*: Returns the minimum value. +*(Object)*: Returns `object`. #### Example ```js -_.min([10, 5, 100, 2, 1000]); -// => 2 +function Dog(name) { + this.name = name; +} + +Dog.prototype.bark = function() { + alert('Woof, woof!'); +}; + +_.forIn(new Dog('Dagny'), function(value, key) { + alert(key); +}); +// => alerts 'name' and 'bark' (order is not guaranteed) ``` * * * @@ -1857,27 +1941,25 @@ _.min([10, 5, 100, 2, 1000]); -### `_.mixin(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3572 "View in source") [Ⓣ][1] +### `_.forOwn(object, callback [, thisArg])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1186 "View in source") [Ⓣ][1] -Adds functions properties of `object` to the `lodash` function and chainable wrapper. +Iterates over `object`'s own enumerable properties, executing the `callback` for each property. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, key, object)*. Callbacks may exit iteration early by explicitly returning `false`. #### Arguments -1. `object` *(Object)*: The object of function properties to add to `lodash`. +1. `object` *(Object)*: The object to iterate over. +2. `callback` *(Function)*: The function called per iteration. +3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. + +#### Returns +*(Object)*: Returns `object`. #### Example ```js -_.mixin({ - 'capitalize': function(string) { - return string.charAt(0).toUpperCase() + string.slice(1).toLowerCase(); - } +_.forOwn({ '0': 'zero', '1': 'one', 'length': 2 }, function(num, key) { + alert(key); }); - -_.capitalize('larry'); -// => 'Larry' - -_('curly').capitalize(); -// => 'Curly' +// => alerts '0', '1', and 'length' (order is not guaranteed) ``` * * * @@ -1887,17 +1969,24 @@ _('curly').capitalize(); -### `_.noConflict()` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3603 "View in source") [Ⓣ][1] +### `_.functions(object)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1203 "View in source") [Ⓣ][1] -Reverts the '_' variable to its previous value and returns a reference to the `lodash` function. +Creates a sorted array of all enumerable properties, own and inherited, of `object` that have function values. + +#### Aliases +*methods* + +#### Arguments +1. `object` *(Object)*: The object to inspect. #### Returns -*(Function)*: Returns the `lodash` function. +*(Array)*: Returns a new array of property names that have function values. #### Example ```js -var lodash = _.noConflict(); +_.functions(_); +// => ['all', 'any', 'bind', 'bindAll', 'clone', 'compact', 'compose', ...] ``` * * * @@ -1907,22 +1996,22 @@ var lodash = _.noConflict(); -### `_.object(keys [, values=[]])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2776 "View in source") [Ⓣ][1] +### `_.has(object, property)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1226 "View in source") [Ⓣ][1] -Creates an object composed from arrays of `keys` and `values`. Pass either a single two dimensional array, i.e. `[[key1, value1], [key2, value2]]`, or two arrays, one of `keys` and one of corresponding `values`. +Checks if the specified object `property` exists and is a direct property, instead of an inherited property. #### Arguments -1. `keys` *(Array)*: The array of keys. -2. `[values=[]]` *(Array)*: The array of values. +1. `object` *(Object)*: The object to check. +2. `property` *(String)*: The property to check for. #### Returns -*(Object)*: Returns an object composed of the given keys and corresponding values. +*(Boolean)*: Returns `true` if key is a direct property, else `false`. #### Example ```js -_.object(['moe', 'larry', 'curly'], [30, 40, 50]); -// => { 'moe': 30, 'larry': 40, 'curly': 50 } +_.has({ 'a': 1, 'b': 2, 'c': 3 }, 'b'); +// => true ``` * * * @@ -1932,28 +2021,21 @@ _.object(['moe', 'larry', 'curly'], [30, 40, 50]); -### `_.omit(object, callback|[prop1, prop2, ..., thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1785 "View in source") [Ⓣ][1] +### `_.invert(object)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L804 "View in source") [Ⓣ][1] -Creates a shallow clone of `object` excluding the specified properties. Property names may be specified as individual arguments or as arrays of property names. If `callback` is passed, it will be executed for each property in the `object`, omitting the properties `callback` returns truthy for. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, key, object)*. +Creates an object composed of the inverted keys and values of the given `object`. #### Arguments -1. `object` *(Object)*: The source object. -2. `callback|[prop1, prop2, ...]` *(Function|String)*: The properties to omit or the function called per iteration. -3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. +1. `object` *(Object)*: The object to invert. #### Returns -*(Object)*: Returns an object without the omitted properties. +*(Object)*: Returns the created inverted object. #### Example ```js -_.omit({ 'name': 'moe', 'age': 40, 'userid': 'moe1' }, 'userid'); -// => { 'name': 'moe', 'age': 40 } - -_.omit({ 'name': 'moe', '_hint': 'knucklehead', '_seed': '96c4eb' }, function(value, key) { - return key.charAt(0) == '_'; -}); -// => { 'name': 'moe' } +_.invert({ 'first': 'Moe', 'second': 'Larry', 'third': 'Curly' }); +// => { 'Moe': 'first', 'Larry': 'second', 'Curly': 'third' } (order is not guaranteed) ``` * * * @@ -1963,23 +2045,24 @@ _.omit({ 'name': 'moe', '_hint': 'knucklehead', '_seed': '96c4eb' }, function(va -### `_.once(func)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3392 "View in source") [Ⓣ][1] +### `_.isArguments(value)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L826 "View in source") [Ⓣ][1] -Creates a function that is restricted to one execution. Repeat calls to the function will return the value of the first call. +Checks if `value` is an `arguments` object. #### Arguments -1. `func` *(Function)*: The function to restrict. +1. `value` *(Mixed)*: The value to check. #### Returns -*(Function)*: Returns the new restricted function. +*(Boolean)*: Returns `true` if the `value` is an `arguments` object, else `false`. #### Example ```js -var initialize = _.once(createApplication); -initialize(); -initialize(); -// Application is only created once. +(function() { return _.isArguments(arguments); })(1, 2, 3); +// => true + +_.isArguments([1, 2, 3]); +// => false ``` * * * @@ -1989,21 +2072,24 @@ initialize(); -### `_.pairs(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1801 "View in source") [Ⓣ][1] +### `_.isArray(value)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L852 "View in source") [Ⓣ][1] -Creates a two dimensional array of the given object's key-value pairs, i.e. `[[key1, value1], [key2, value2]]`. +Checks if `value` is an array. #### Arguments -1. `object` *(Object)*: The object to inspect. +1. `value` *(Mixed)*: The value to check. #### Returns -*(Array)*: Returns new array of key-value pairs. +*(Boolean)*: Returns `true` if the `value` is an array, else `false`. #### Example ```js -_.pairs({ 'moe': 30, 'larry': 40, 'curly': 50 }); -// => [['moe', 30], ['larry', 40], ['curly', 50]] (order is not guaranteed) +(function() { return _.isArray(arguments); })(); +// => false + +_.isArray([1, 2, 3]); +// => true ``` * * * @@ -2013,24 +2099,21 @@ _.pairs({ 'moe': 30, 'larry': 40, 'curly': 50 }); -### `_.partial(func [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3427 "View in source") [Ⓣ][1] +### `_.isBoolean(value)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1243 "View in source") [Ⓣ][1] -Creates a function that, when called, invokes `func` with any additional `partial` arguments prepended to those passed to the new function. This method is similar to `bind`, except it does **not** alter the `this` binding. +Checks if `value` is a boolean *(`true` or `false`)* value. #### Arguments -1. `func` *(Function)*: The function to partially apply arguments to. -2. `[arg1, arg2, ...]` *(Mixed)*: Arguments to be partially applied. +1. `value` *(Mixed)*: The value to check. #### Returns -*(Function)*: Returns the new partially applied function. +*(Boolean)*: Returns `true` if the `value` is a boolean value, else `false`. #### Example ```js -var greet = function(greeting, name) { return greeting + ': ' + name; }; -var hi = _.partial(greet, 'hi'); -hi('moe'); -// => 'hi: moe' +_.isBoolean(null); +// => false ``` * * * @@ -2040,28 +2123,21 @@ hi('moe'); -### `_.pick(object, callback|[prop1, prop2, ..., thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1832 "View in source") [Ⓣ][1] +### `_.isDate(value)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1260 "View in source") [Ⓣ][1] -Creates a shallow clone of `object` composed of the specified properties. Property names may be specified as individual arguments or as arrays of property names. If `callback` is passed, it will be executed for each property in the `object`, picking the properties `callback` returns truthy for. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, key, object)*. +Checks if `value` is a date. #### Arguments -1. `object` *(Object)*: The source object. -2. `callback|[prop1, prop2, ...]` *(Function|String)*: The properties to pick or the function called per iteration. -3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. +1. `value` *(Mixed)*: The value to check. #### Returns -*(Object)*: Returns an object composed of the picked properties. +*(Boolean)*: Returns `true` if the `value` is a date, else `false`. #### Example ```js -_.pick({ 'name': 'moe', 'age': 40, 'userid': 'moe1' }, 'name', 'age'); -// => { 'name': 'moe', 'age': 40 } - -_.pick({ 'name': 'moe', '_hint': 'knucklehead', '_seed': '96c4eb' }, function(value, key) { - return key.charAt(0) != '_'; -}); -// => { 'name': 'moe' } +_.isDate(new Date); +// => true ``` * * * @@ -2071,28 +2147,21 @@ _.pick({ 'name': 'moe', '_hint': 'knucklehead', '_seed': '96c4eb' }, function(va -### `_.pluck(collection, property)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2132 "View in source") [Ⓣ][1] +### `_.isElement(value)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1277 "View in source") [Ⓣ][1] -Retrieves the value of a specified property from all elements in the `collection`. +Checks if `value` is a DOM element. #### Arguments -1. `collection` *(Array|Object|String)*: The collection to iterate over. -2. `property` *(String)*: The property to pluck. +1. `value` *(Mixed)*: The value to check. #### Returns -*(Array)*: Returns a new array of property values. +*(Boolean)*: Returns `true` if the `value` is a DOM element, else `false`. #### Example ```js -var stooges = [ - { 'name': 'moe', 'age': 40 }, - { 'name': 'larry', 'age': 50 }, - { 'name': 'curly', 'age': 60 } -]; - -_.pluck(stooges, 'name'); -// => ['moe', 'larry', 'curly'] +_.isElement(document.body); +// => true ``` * * * @@ -2102,25 +2171,27 @@ _.pluck(stooges, 'name'); -### `_.random([min=0, max=1])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3626 "View in source") [Ⓣ][1] +### `_.isEmpty(value)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1302 "View in source") [Ⓣ][1] -Produces a random number between `min` and `max` *(inclusive)*. If only one argument is passed, a number between `0` and the given number will be returned. +Checks if `value` is empty. Arrays, strings, or `arguments` objects with a length of `0` and objects with no own enumerable properties are considered "empty". #### Arguments -1. `[min=0]` *(Number)*: The minimum possible value. -2. `[max=1]` *(Number)*: The maximum possible value. +1. `value` *(Array|Object|String)*: The value to inspect. #### Returns -*(Number)*: Returns a random number. +*(Boolean)*: Returns `true` if the `value` is empty, else `false`. #### Example ```js -_.random(0, 5); -// => a number between 1 and 5 +_.isEmpty([1, 2, 3]); +// => false -_.random(5); -// => also a number between 1 and 5 +_.isEmpty({}); +// => true + +_.isEmpty(''); +// => true ``` * * * @@ -2130,35 +2201,28 @@ _.random(5); -### `_.range([start=0], end [, step=1])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2820 "View in source") [Ⓣ][1] +### `_.isEqual(a, b)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1341 "View in source") [Ⓣ][1] -Creates an array of numbers *(positive and/or negative)* progressing from `start` up to but not including `stop`. This method is a port of Python's `range()` function. See http://docs.python.org/library/functions.html#range. +Performs a deep comparison between two values to determine if they are equivalent to each other. #### Arguments -1. `[start=0]` *(Number)*: The start of the range. -2. `end` *(Number)*: The end of the range. -3. `[step=1]` *(Number)*: The value to increment or descrement by. +1. `a` *(Mixed)*: The value to compare. +2. `b` *(Mixed)*: The other value to compare. #### Returns -*(Array)*: Returns a new range array. +*(Boolean)*: Returns `true` if the values are equvalent, else `false`. #### Example ```js -_.range(10); -// => [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] - -_.range(1, 11); -// => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] - -_.range(0, 30, 5); -// => [0, 5, 10, 15, 20, 25] +var moe = { 'name': 'moe', 'luckyNumbers': [13, 27, 34] }; +var clone = { 'name': 'moe', 'luckyNumbers': [13, 27, 34] }; -_.range(0, -10, -1); -// => [0, -1, -2, -3, -4, -5, -6, -7, -8, -9] +moe == clone; +// => false -_.range(0); -// => [] +_.isEqual(moe, clone); +// => true ``` * * * @@ -2168,27 +2232,27 @@ _.range(0); -### `_.reduce(collection, callback [, accumulator, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2160 "View in source") [Ⓣ][1] - -Boils down a `collection` to a single value. The initial state of the reduction is `accumulator` and each successive step of it should be returned by the `callback`. The `callback` is bound to `thisArg` and invoked with `4` arguments; for arrays they are *(accumulator, value, index|key, collection)*. +### `_.isFinite(value)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1498 "View in source") [Ⓣ][1] -#### Aliases -*foldl, inject* +Checks if `value` is a finite number. Note: This is not the same as native `isFinite`, which will return true for booleans and other values. See http://es5.github.com/#x15.1.2.5. #### Arguments -1. `collection` *(Array|Object|String)*: The collection to iterate over. -2. `callback` *(Function)*: The function called per iteration. -3. `[accumulator]` *(Mixed)*: Initial value of the accumulator. -4. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. +1. `value` *(Mixed)*: The value to check. #### Returns -*(Mixed)*: Returns the accumulated value. +*(Boolean)*: Returns `true` if the `value` is a finite number, else `false`. #### Example ```js -var sum = _.reduce([1, 2, 3], function(memo, num) { return memo + num; }); -// => 6 +_.isFinite(-101); +// => true + +_.isFinite('10'); +// => false + +_.isFinite(Infinity); +// => false ``` * * * @@ -2198,28 +2262,21 @@ var sum = _.reduce([1, 2, 3], function(memo, num) { return memo + num; }); -### `_.reduceRight(collection, callback [, accumulator, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2197 "View in source") [Ⓣ][1] - -The right-associative version of `_.reduce`. +### `_.isFunction(value)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L869 "View in source") [Ⓣ][1] -#### Aliases -*foldr* +Checks if `value` is a function. #### Arguments -1. `collection` *(Array|Object|String)*: The collection to iterate over. -2. `callback` *(Function)*: The function called per iteration. -3. `[accumulator]` *(Mixed)*: Initial value of the accumulator. -4. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. +1. `value` *(Mixed)*: The value to check. #### Returns -*(Mixed)*: Returns the accumulated value. +*(Boolean)*: Returns `true` if the `value` is a function, else `false`. #### Example ```js -var list = [[0, 1], [2, 3], [4, 5]]; -var flat = _.reduceRight(list, function(a, b) { return a.concat(b); }, []); -// => [4, 5, 2, 3, 0, 1] +_.isFunction(_); +// => true ``` * * * @@ -2229,23 +2286,30 @@ var flat = _.reduceRight(list, function(a, b) { return a.concat(b); }, []); -### `_.reject(collection [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2234 "View in source") [Ⓣ][1] +### `_.isNaN(value)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1556 "View in source") [Ⓣ][1] -The opposite of `_.filter`, this method returns the values of a `collection` that `callback` does **not** return truthy for. +Checks if `value` is `NaN`. Note: This is not the same as native `isNaN`, which will return true for `undefined` and other values. See http://es5.github.com/#x15.1.2.4. #### Arguments -1. `collection` *(Array|Object|String)*: The collection to iterate over. -2. `[callback=identity]` *(Function)*: The function called per iteration. -3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. +1. `value` *(Mixed)*: The value to check. #### Returns -*(Array)*: Returns a new array of elements that did **not** pass the callback check. +*(Boolean)*: Returns `true` if the `value` is `NaN`, else `false`. #### Example ```js -var odds = _.reject([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }); -// => [1, 3, 5] +_.isNaN(NaN); +// => true + +_.isNaN(new Number(NaN)); +// => true + +isNaN(undefined); +// => true + +_.isNaN(undefined); +// => false ``` * * * @@ -2255,25 +2319,24 @@ var odds = _.reject([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }); -### `_.rest(array [, n])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2859 "View in source") [Ⓣ][1] - -The opposite of `_.initial`, this method gets all but the first value of `array`. Pass `n` to exclude the first `n` values from the result. +### `_.isNull(value)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1579 "View in source") [Ⓣ][1] -#### Aliases -*drop, tail* +Checks if `value` is `null`. #### Arguments -1. `array` *(Array)*: The array to query. -2. `[n]` *(Number)*: The number of elements to return. +1. `value` *(Mixed)*: The value to check. #### Returns -*(Array)*: Returns all but the first value or `n` values of `array`. +*(Boolean)*: Returns `true` if the `value` is `null`, else `false`. #### Example ```js -_.rest([3, 2, 1]); -// => [2, 1] +_.isNull(null); +// => true + +_.isNull(undefined); +// => false ``` * * * @@ -2283,32 +2346,21 @@ _.rest([3, 2, 1]); -### `_.result(object, property)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3665 "View in source") [Ⓣ][1] - -Resolves the value of `property` on `object`. If `property` is a function it will be invoked and its result returned, else the property value is returned. If `object` is falsey, then `null` is returned. - -#### Arguments -1. `object` *(Object)*: The object to inspect. -2. `property` *(String)*: The property to get the value of. +### `_.isNumber(value)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1596 "View in source") [Ⓣ][1] -#### Returns -*(Mixed)*: Returns the resolved value. +Checks if `value` is a number. -#### Example -```js -var object = { - 'cheese': 'crumpets', - 'stuff': function() { - return 'nonsense'; - } -}; +#### Arguments +1. `value` *(Mixed)*: The value to check. -_.result(object, 'cheese'); -// => 'crumpets' +#### Returns +*(Boolean)*: Returns `true` if the `value` is a number, else `false`. -_.result(object, 'stuff'); -// => 'nonsense' +#### Example +```js +_.isNumber(8.4 * 5); +// => true ``` * * * @@ -2318,21 +2370,27 @@ _.result(object, 'stuff'); -### `_.shuffle(array)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2879 "View in source") [Ⓣ][1] +### `_.isObject(value)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1522 "View in source") [Ⓣ][1] -Creates an array of shuffled `array` values, using a version of the Fisher-Yates shuffle. See http://en.wikipedia.org/wiki/Fisher-Yates_shuffle. +Checks if `value` is the language type of Object. *(e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)* #### Arguments -1. `array` *(Array)*: The array to shuffle. +1. `value` *(Mixed)*: The value to check. #### Returns -*(Array)*: Returns a new shuffled array. +*(Boolean)*: Returns `true` if the `value` is an object, else `false`. #### Example ```js -_.shuffle([1, 2, 3, 4, 5, 6]); -// => [4, 1, 6, 3, 5, 2] +_.isObject({}); +// => true + +_.isObject([1, 2, 3]); +// => true + +_.isObject(1); +// => false ``` * * * @@ -2342,27 +2400,32 @@ _.shuffle([1, 2, 3, 4, 5, 6]); -### `_.size(collection)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2258 "View in source") [Ⓣ][1] +### `_.isPlainObject(value)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L903 "View in source") [Ⓣ][1] -Gets the size of the `collection` by returning `collection.length` for arrays and array-like objects or the number of own enumerable properties for objects. +Checks if a given `value` is an object created by the `Object` constructor. #### Arguments -1. `collection` *(Array|Object|String)*: The collection to inspect. +1. `value` *(Mixed)*: The value to check. #### Returns -*(Number)*: Returns `collection.length` or number of own enumerable properties. +*(Boolean)*: Returns `true` if `value` is a plain object, else `false`. #### Example ```js -_.size([1, 2]); -// => 2 +function Stooge(name, age) { + this.name = name; + this.age = age; +} -_.size({ 'one': 1, 'two': 2, 'three': 3 }); -// => 3 +_.isPlainObject(new Stooge('moe', 40)); +// false -_.size('curly'); -// => 5 +_.isPlainObject([1, 2, 3]); +// false + +_.isPlainObject({ 'name': 'moe', 'age': 40 }); +// => true ``` * * * @@ -2372,25 +2435,20 @@ _.size('curly'); -### `_.some(collection [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2283 "View in source") [Ⓣ][1] - -Checks if the `callback` returns a truthy value for **any** element of a `collection`. The function returns as soon as it finds passing value, and does not iterate over the entire `collection`. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. +### `_.isRegExp(value)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1613 "View in source") [Ⓣ][1] -#### Aliases -*any* +Checks if `value` is a regular expression. #### Arguments -1. `collection` *(Array|Object|String)*: The collection to iterate over. -2. `[callback=identity]` *(Function)*: The function called per iteration. -3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. +1. `value` *(Mixed)*: The value to check. #### Returns -*(Boolean)*: Returns `true` if any element passes the callback check, else `false`. +*(Boolean)*: Returns `true` if the `value` is a regular expression, else `false`. #### Example ```js -_.some([null, 0, 'yes', false]); +_.isRegExp(/moe/); // => true ``` @@ -2401,29 +2459,21 @@ _.some([null, 0, 'yes', false]); -### `_.sortBy(collection, callback|property [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2313 "View in source") [Ⓣ][1] +### `_.isString(value)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1630 "View in source") [Ⓣ][1] -Creates an array, stable sorted in ascending order by the results of running each element of `collection` through a `callback`. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. The `callback` argument may also be the name of a property to sort by *(e.g. 'length')*. +Checks if `value` is a string. #### Arguments -1. `collection` *(Array|Object|String)*: The collection to iterate over. -2. `callback|property` *(Function|String)*: The function called per iteration or property name to sort by. -3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. +1. `value` *(Mixed)*: The value to check. #### Returns -*(Array)*: Returns a new array of sorted elements. +*(Boolean)*: Returns `true` if the `value` is a string, else `false`. #### Example ```js -_.sortBy([1, 2, 3], function(num) { return Math.sin(num); }); -// => [3, 1, 2] - -_.sortBy([1, 2, 3], function(num) { return this.sin(num); }, Math); -// => [3, 1, 2] - -_.sortBy(['larry', 'brendan', 'moe'], 'length'); -// => ['moe', 'larry', 'brendan'] +_.isString('moe'); +// => true ``` * * * @@ -2433,41 +2483,21 @@ _.sortBy(['larry', 'brendan', 'moe'], 'length'); -### `_.sortedIndex(array, value [, callback=identity|property, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2932 "View in source") [Ⓣ][1] +### `_.isUndefined(value)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1648 "View in source") [Ⓣ][1] -Uses a binary search to determine the smallest index at which the `value` should be inserted into `array` in order to maintain the sort order of the sorted `array`. If `callback` is passed, it will be executed for `value` and each element in `array` to compute their sort ranking. The `callback` is bound to `thisArg` and invoked with one argument; *(value)*. The `callback` argument may also be the name of a property to order by. +Checks if `value` is `undefined`. #### Arguments -1. `array` *(Array)*: The array to iterate over. -2. `value` *(Mixed)*: The value to evaluate. -3. `[callback=identity|property]` *(Function|String)*: The function called per iteration or property name to order by. -4. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. +1. `value` *(Mixed)*: The value to check. #### Returns -*(Number)*: Returns the index at which the value should be inserted into `array`. +*(Boolean)*: Returns `true` if the `value` is `undefined`, else `false`. #### Example ```js -_.sortedIndex([20, 30, 50], 40); -// => 2 - -_.sortedIndex([{ 'x': 20 }, { 'x': 30 }, { 'x': 50 }], { 'x': 40 }, 'x'); -// => 2 - -var dict = { - 'wordToNumber': { 'twenty': 20, 'thirty': 30, 'fourty': 40, 'fifty': 50 } -}; - -_.sortedIndex(['twenty', 'thirty', 'fifty'], 'fourty', function(word) { - return dict.wordToNumber[word]; -}); -// => 2 - -_.sortedIndex(['twenty', 'thirty', 'fifty'], 'fourty', function(word) { - return this.wordToNumber[word]; -}, dict); -// => 2 +_.isUndefined(void 0); +// => true ``` * * * @@ -2477,27 +2507,21 @@ _.sortedIndex(['twenty', 'thirty', 'fifty'], 'fourty', function(word) { -### `_.tap(value, interceptor)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3954 "View in source") [Ⓣ][1] +### `_.keys(object)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1665 "View in source") [Ⓣ][1] -Invokes `interceptor` with the `value` as the first argument, and then returns `value`. The purpose of this method is to "tap into" a method chain, in order to perform operations on intermediate results within the chain. +Creates an array composed of the own enumerable property names of `object`. #### Arguments -1. `value` *(Mixed)*: The value to pass to `interceptor`. -2. `interceptor` *(Function)*: The function to invoke. +1. `object` *(Object)*: The object to inspect. #### Returns -*(Mixed)*: Returns `value`. +*(Array)*: Returns a new array of property names. #### Example ```js -_.chain([1, 2, 3, 200]) - .filter(function(num) { return num % 2 == 0; }) - .tap(alert) - .map(function(num) { return num * num }) - .value(); -// => // [2, 200] (alerted) -// => [4, 40000] +_.keys({ 'one': 1, 'two': 2, 'three': 3 }); +// => ['one', 'two', 'three'] (order is not guaranteed) ``` * * * @@ -2507,62 +2531,32 @@ _.chain([1, 2, 3, 200]) -### `_.template(text, data, options)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3735 "View in source") [Ⓣ][1] +### `_.merge(object [, source1, source2, ...])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1708 "View in source") [Ⓣ][1] -A micro-templating method that handles arbitrary delimiters, preserves whitespace, and correctly escapes quotes within interpolated code. Note: In the development build `_.template` utilizes sourceURLs for easier debugging. See http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl Note: Lo-Dash may be used in Chrome extensions by either creating a `lodash csp` build and avoiding `_.template` use, or loading Lo-Dash in a sandboxed page. See http://developer.chrome.com/trunk/extensions/sandboxingEval.html +Merges enumerable properties of the source object(s) into the `destination` object. Subsequent sources will overwrite propery assignments of previous sources. #### Arguments -1. `text` *(String)*: The template text. -2. `data` *(Obect)*: The data object used to populate the text. -3. `options` *(Object)*: The options object. +1. `object` *(Object)*: The destination object. +2. `[source1, source2, ...]` *(Object)*: The source objects. #### Returns -*(Function, String)*: Returns a compiled function when no `data` object is given, else it returns the interpolated text. +*(Object)*: Returns the destination object. #### Example ```js -// using a compiled template -var compiled = _.template('hello: <%= name %>'); -compiled({ 'name': 'moe' }); -// => 'hello: moe' - -var list = '<% _.forEach(people, function(name) { %>