UNPKG

flavor-js

Version:

FlavorJS the definitive JS natives chainable extensions methods (based on lodash & ES6)

2,595 lines (877 loc) 140 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>array - Documentation</title> <script src="scripts/prettify/prettify.js"></script> <script src="scripts/prettify/lang-css.js"></script> <!--[if lt IE 9]> <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <link type="text/css" rel="stylesheet" href="styles/prettify.css"> <link type="text/css" rel="stylesheet" href="styles/jsdoc.css"> </head> <body> <input type="checkbox" id="nav-trigger" class="nav-trigger" /> <label for="nav-trigger" class="navicon-button x"> <div class="navicon"></div> </label> <label for="nav-trigger" class="overlay"></label> <nav> <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="FlavorJS.html">FlavorJS</a><ul class='methods'><li data-type='method'><a href="FlavorJS.html#delay">delay</a></li><li data-type='method'><a href="FlavorJS.html#extendArray">extendArray</a></li><li data-type='method'><a href="FlavorJS.html#extendBoolean">extendBoolean</a></li><li data-type='method'><a href="FlavorJS.html#extendDate">extendDate</a></li><li data-type='method'><a href="FlavorJS.html#extendFunction">extendFunction</a></li><li data-type='method'><a href="FlavorJS.html#extendLodash">extendLodash</a></li><li data-type='method'><a href="FlavorJS.html#extendNumber">extendNumber</a></li><li data-type='method'><a href="FlavorJS.html#extendObject">extendObject</a></li><li data-type='method'><a href="FlavorJS.html#extendPrototype">extendPrototype</a></li><li data-type='method'><a href="FlavorJS.html#extendPrototypeProperty">extendPrototypeProperty</a></li><li data-type='method'><a href="FlavorJS.html#extendString">extendString</a></li><li data-type='method'><a href="FlavorJS.html#init">init</a></li></ul></li></ul><h3>Namespaces</h3><ul><li><a href="array.html">array</a><ul class='methods'><li data-type='method'><a href="array.html#clone">clone</a></li><li data-type='method'><a href="array.html#concat">concat</a></li><li data-type='method'><a href="array.html#contains">contains</a></li><li data-type='method'><a href="array.html#containsBy">containsBy</a></li><li data-type='method'><a href="array.html#countBy">countBy</a></li><li data-type='method'><a href="array.html#cut">cut</a></li><li data-type='method'><a href="array.html#deepFindBy">deepFindBy</a></li><li data-type='method'><a href="array.html#deepMap">deepMap</a></li><li data-type='method'><a href="array.html#deepSortBy">deepSortBy</a></li><li data-type='method'><a href="array.html#diff">diff</a></li><li data-type='method'><a href="array.html#diffBy">diffBy</a></li><li data-type='method'><a href="array.html#distinct">distinct</a></li><li data-type='method'><a href="array.html#each">each</a></li><li data-type='method'><a href="array.html#filterBy">filterBy</a></li><li data-type='method'><a href="array.html#findBy">findBy</a></li><li data-type='method'><a href="array.html#first">first</a></li><li data-type='method'><a href="array.html#flatten">flatten</a></li><li data-type='method'><a href="array.html#indexBy">indexBy</a></li><li data-type='method'><a href="array.html#intersection">intersection</a></li><li data-type='method'><a href="array.html#isArray">isArray</a></li><li data-type='method'><a href="array.html#last">last</a></li><li data-type='method'><a href="array.html#lorem">lorem</a></li><li data-type='method'><a href="array.html#maxBy">maxBy</a></li><li data-type='method'><a href="array.html#pull">pull</a></li><li data-type='method'><a href="array.html#pullBy">pullBy</a></li><li data-type='method'><a href="array.html#random">random</a></li><li data-type='method'><a href="array.html#removeBy">removeBy</a></li><li data-type='method'><a href="array.html#shuffle">shuffle</a></li><li data-type='method'><a href="array.html#sortBy">sortBy</a></li><li data-type='method'><a href="array.html#split">split</a></li><li data-type='method'><a href="array.html#sum">sum</a></li><li data-type='method'><a href="array.html#tail">tail</a></li><li data-type='method'><a href="array.html#tail">tail</a></li><li data-type='method'><a href="array.html#union">union</a></li></ul></li><li><a href="boolean.html">boolean</a><ul class='methods'><li data-type='method'><a href="boolean.html#isBoolean">isBoolean</a></li><li data-type='method'><a href="boolean.html#random">random</a></li></ul></li><li><a href="date.html">date</a><ul class='methods'><li data-type='method'><a href="date.html#isDate">isDate</a></li><li data-type='method'><a href="date.html#random">random</a></li><li data-type='method'><a href="date.html#toTimestamp">toTimestamp</a></li></ul></li><li><a href="function.html">function</a><ul class='methods'><li data-type='method'><a href="function.html#isFunction">isFunction</a></li><li data-type='method'><a href="function.html#proxy">proxy</a></li></ul></li><li><a href="lodash.html">lodash</a><ul class='methods'><li data-type='method'><a href="lodash.html#deepFindBy">deepFindBy</a></li><li data-type='method'><a href="lodash.html#deepMap">deepMap</a></li><li data-type='method'><a href="lodash.html#deepOrderBy">deepOrderBy</a></li><li data-type='method'><a href="lodash.html#filterByValues">filterByValues</a></li><li data-type='method'><a href="lodash.html#isPercentage">isPercentage</a></li><li data-type='method'><a href="lodash.html#parsePercentage">parsePercentage</a></li><li data-type='method'><a href="lodash.html#pullAllByComparator">pullAllByComparator</a></li><li data-type='method'><a href="lodash.html#timesRange">timesRange</a></li><li data-type='method'><a href="lodash.html#timesReverse">timesReverse</a></li></ul></li><li><a href="number.html">number</a><ul class='methods'><li data-type='method'><a href="number.html#between">between</a></li><li data-type='method'><a href="number.html#degreeDiff">degreeDiff</a></li><li data-type='method'><a href="number.html#degreeDir">degreeDir</a></li><li data-type='method'><a href="number.html#degreeWrap">degreeWrap</a></li><li data-type='method'><a href="number.html#floor">floor</a></li><li data-type='method'><a href="number.html#fromRoman">fromRoman</a></li><li data-type='method'><a href="number.html#isNumber">isNumber</a></li><li data-type='method'><a href="number.html#parse">parse</a></li><li data-type='method'><a href="number.html#random">random</a></li><li data-type='method'><a href="number.html#range">range</a></li><li data-type='method'><a href="number.html#round">round</a></li><li data-type='method'><a href="number.html#round">round</a></li><li data-type='method'><a href="number.html#times">times</a></li><li data-type='method'><a href="number.html#toAbsolute">toAbsolute</a></li><li data-type='method'><a href="number.html#toCurrency">toCurrency</a></li><li data-type='method'><a href="number.html#toFileSize">toFileSize</a></li><li data-type='method'><a href="number.html#toRoman">toRoman</a></li><li data-type='method'><a href="number.html#toSymbolString">toSymbolString</a></li></ul></li><li><a href="object.html">object</a><ul class='methods'><li data-type='method'><a href="object.html#clone">clone</a></li><li data-type='method'><a href="object.html#each">each</a></li><li data-type='method'><a href="object.html#inherit">inherit</a></li><li data-type='method'><a href="object.html#isObject">isObject</a></li><li data-type='method'><a href="object.html#omit">omit</a></li><li data-type='method'><a href="object.html#path">path</a></li><li data-type='method'><a href="object.html#pick">pick</a></li></ul></li><li><a href="string.html">string</a><ul class='methods'><li data-type='method'><a href="string.html#camelCase">camelCase</a></li><li data-type='method'><a href="string.html#capitalize">capitalize</a></li><li data-type='method'><a href="string.html#contains">contains</a></li><li data-type='method'><a href="string.html#decodeURI">decodeURI</a></li><li data-type='method'><a href="string.html#encodeURI">encodeURI</a></li><li data-type='method'><a href="string.html#endsWith">endsWith</a></li><li data-type='method'><a href="string.html#escapeHTML">escapeHTML</a></li><li data-type='method'><a href="string.html#escapeHTML">escapeHTML</a></li><li data-type='method'><a href="string.html#extractDomain">extractDomain</a></li><li data-type='method'><a href="string.html#extractFileExtension">extractFileExtension</a></li><li data-type='method'><a href="string.html#extractQueryString">extractQueryString</a></li><li data-type='method'><a href="string.html#guid">guid</a></li><li data-type='method'><a href="string.html#isRoman">isRoman</a></li><li data-type='method'><a href="string.html#isString">isString</a></li><li data-type='method'><a href="string.html#isUrl">isUrl</a></li><li data-type='method'><a href="string.html#pad">pad</a></li><li data-type='method'><a href="string.html#padLeft">padLeft</a></li><li data-type='method'><a href="string.html#padRight">padRight</a></li><li data-type='method'><a href="string.html#parsePercentage">parsePercentage</a></li><li data-type='method'><a href="string.html#parsePercentage">parsePercentage</a></li><li data-type='method'><a href="string.html#replaceAll">replaceAll</a></li><li data-type='method'><a href="string.html#slugify">slugify</a></li><li data-type='method'><a href="string.html#startsWith">startsWith</a></li><li data-type='method'><a href="string.html#stripTags">stripTags</a></li><li data-type='method'><a href="string.html#toArray">toArray</a></li><li data-type='method'><a href="string.html#toInt">toInt</a></li></ul></li></ul><h3><a href="global.html">Global</a></h3> </nav> <div id="main"> <h1 class="page-title">array</h1> <section> <header> <h2> array </h2> </header> <article> <div class="container-overview"> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="Extensions_array.js.html">Extensions/array.js</a>, <a href="Extensions_array.js.html#line3">line 3</a> </li></ul></dd> </dl> <div class="description">the JS native Array class</div> </div> <h3 class="subsection-title">Methods</h3> <h4 class="name" id="clone"><span class="type-signature"></span>clone<span class="signature">(a)</span><span class="type-signature"> &rarr; {<a href="array.html">array</a>}</span></h4> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="Extensions_array.js.html">Extensions/array.js</a>, <a href="Extensions_array.js.html#line1321">line 1321</a> </li></ul></dd> </dl> <div class="description"> clones an array </div> <h5>Example</h5> <p class="code-caption">eg. usage</p> <pre class="prettyprint"><code>var collection = [ {type: 'a', value: 1}, {type: 'b', value: 8}, {type: 'c', value: 5}, {type: 'd', value: 7}, {type: 'e', value: 9}, {type: 'f', value: 3}, ]; var clone = Array.clone(collection); // or var clone = collection.clone(); console.log(collection === clone); // false;</code></pre> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>a</code></td> <td class="type"> <span class="param-type"><a href="array.html">array</a></span> </td> <td class="description last">the array</td> </tr> </tbody> </table> <h5>Returns:</h5> <dl class="param-type"> <dt> Type </dt> <dd> <span class="param-type"><a href="array.html">array</a></span> </dd> </dl> <h4 class="name" id="concat"><span class="type-signature"></span>concat<span class="signature">(a, ac)</span><span class="type-signature"> &rarr; {<a href="array.html">array</a>}</span></h4> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="Extensions_array.js.html">Extensions/array.js</a>, <a href="Extensions_array.js.html#line58">line 58</a> </li></ul></dd> </dl> <div class="description"> concatenates two arrays </div> <h5>Example</h5> <p class="code-caption">eg. usage</p> <pre class="prettyprint"><code>var arr = ['a', 'e', 'i', 'o', 'u']; console.log(Array.concat(arr, ['b', 'c', 'd']); // ['a', 'e', 'i', 'o', 'u', 'b', 'c', 'd'] console.log(arr.concat(['b', 'c', 'd']); // ['a', 'e', 'i', 'o', 'u', 'b', 'c', 'd']</code></pre> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>a</code></td> <td class="type"> <span class="param-type"><a href="array.html">array</a></span> | <span class="param-type">*</span> </td> <td class="description last">the array to be concatenated</td> </tr> <tr> <td class="name"><code>ac</code></td> <td class="type"> <span class="param-type"><a href="array.html">array</a></span> | <span class="param-type">*</span> </td> <td class="description last">the array to concatenate or the item to concatenate</td> </tr> </tbody> </table> <h5>Returns:</h5> <dl class="param-type"> <dt> Type </dt> <dd> <span class="param-type"><a href="array.html">array</a></span> </dd> </dl> <h4 class="name" id="contains"><span class="type-signature"></span>contains<span class="signature">(a, item, all<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &rarr; {<a href="boolean.html">boolean</a>}</span></h4> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="Extensions_array.js.html">Extensions/array.js</a>, <a href="Extensions_array.js.html#line28">line 28</a> </li></ul></dd> </dl> <div class="description"> checks if an Array contains something </div> <h5>Example</h5> <p class="code-caption">eg. usage</p> <pre class="prettyprint"><code>var arr = ['a', 'e', 'i', 'o', 'u']; console.log(Array.contains(arr, 'b')); // false console.log(Array.contains(arr, 'a')); // true console.log(Array.contains(arr, ['a', 'b', 'e']); // true console.log(Array.contains(arr, ['a', 'b', 'e'], true); // false console.log(arr.contains('b')); // false console.log(arr.contains('a')); // true console.log(arr.contains(['a', 'b', 'e']); // true console.log(arr.contains(['a', 'b', 'e'], true); // false</code></pre> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Attributes</th> <th>Default</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>a</code></td> <td class="type"> <span class="param-type"><a href="array.html">array</a></span> </td> <td class="attributes"> </td> <td class="default"> </td> <td class="description last">the array to be checked</td> </tr> <tr> <td class="name"><code>item</code></td> <td class="type"> <span class="param-type"><a href="array.html">array</a></span> | <span class="param-type">*</span> </td> <td class="attributes"> </td> <td class="default"> </td> <td class="description last">can be anything or an array of anything</td> </tr> <tr> <td class="name"><code>all</code></td> <td class="type"> <span class="param-type"><a href="boolean.html">boolean</a></span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> <code>false</code> </td> <td class="description last">specify to check if the array must contain all items</td> </tr> </tbody> </table> <h5>Returns:</h5> <dl class="param-type"> <dt> Type </dt> <dd> <span class="param-type"><a href="boolean.html">boolean</a></span> </dd> </dl> <h4 class="name" id="containsBy"><span class="type-signature"></span>containsBy<span class="signature">(a, propName, propValue<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &rarr; {any|null}</span></h4> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="Extensions_array.js.html">Extensions/array.js</a>, <a href="Extensions_array.js.html#line631">line 631</a> </li></ul></dd> </dl> <div class="description"> checks if an array contains an item by propName/propValue pair or predicate, </div> <h5>Example</h5> <p class="code-caption">eg. usage</p> <pre class="prettyprint"><code>var collection = [ {type: 'a', value: 'a'}, {type: 'a', value: 'a-2-1'}, {type: 'a', value: 'a-1-3'}, {type: 'c', value: 'c'}, {type: 'a', value: 'a-1-1'}, {type: 'b', value: 'b'}, {type: 'b', value: 'b-1-1'}, ]; console.log(Array.containsBy(collection, 'value', 'a-2-2')); // false console.log(collection.containsBy('value', 'a-2-2')); // same as above console.log(Array.containsBy(collection, 'value', 'a-2-1')); // true console.log(collection.containsBy('value', 'a-2-1')); // same as above console.log(Array.containsBy(collection, function(item) { return item.type === 'c'; })); // true console.log(collection.containsBy(function(item) { return item.type === 'c'; })); // same as above</code></pre> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Attributes</th> <th>Default</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>a</code></td> <td class="type"> <span class="param-type"><a href="array.html">array</a></span> </td> <td class="attributes"> </td> <td class="default"> </td> <td class="description last"></td> </tr> <tr> <td class="name"><code>propName</code></td> <td class="type"> <span class="param-type"><a href="string.html">string</a></span> | <span class="param-type"><a href="function.html">function</a></span> </td> <td class="attributes"> </td> <td class="default"> </td> <td class="description last"></td> </tr> <tr> <td class="name"><code>propValue</code></td> <td class="type"> <span class="param-type">any</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> <code>null</code> </td> <td class="description last"></td> </tr> </tbody> </table> <h5>Returns:</h5> <dl class="param-type"> <dt> Type </dt> <dd> <span class="param-type">any</span> | <span class="param-type">null</span> </dd> </dl> <h4 class="name" id="countBy"><span class="type-signature"></span>countBy<span class="signature">(a, propName, propValue<span class="signature-attributes">opt</span>, falseValues<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &rarr; {<a href="number.html">number</a>}</span></h4> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="Extensions_array.js.html">Extensions/array.js</a>, <a href="Extensions_array.js.html#line673">line 673</a> </li></ul></dd> </dl> <div class="description"> counts items in array that respects propName/propValue pair or predicate, </div> <h5>Example</h5> <p class="code-caption">eg. usage</p> <pre class="prettyprint"><code>var collection = [ {type: 'a', value: 'a'}, {type: 'a', value: 'a-2-1'}, {type: 'a', value: 'a-1-3'}, {type: 'c', value: 'c'}, {type: 'a', value: 'a-1-1'}, {type: 'b', value: 'b'}, {type: 'b', value: 'b-1-1'}, ]; console.log(Array.countBy(collection, 'type', 'a')); // 4 console.log(collection.countBy('type', 'a')); // same as above console.log(Array.countBy(collection, 'type', 'a', true)); // 3, it counts false values console.log(collection.countBy('type', 'a', true)); // same as above console.log(Array.countBy(collection, function(item) { return item.type === 'b'; })); // 2 console.log(collection.countBy(function(item) { return item.type === 'b'; })); // same as above console.log(Array.countBy(collection, function(item) { return item.type === 'b'; }, null, true)); // 5, it counts false values console.log(collection.countBy(function(item) { return item.type === 'b'; }, null, true)); // same as above</code></pre> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Attributes</th> <th>Default</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>a</code></td> <td class="type"> <span class="param-type"><a href="array.html">array</a></span> </td> <td class="attributes"> </td> <td class="default"> </td> <td class="description last"></td> </tr> <tr> <td class="name"><code>propName</code></td> <td class="type"> <span class="param-type"><a href="string.html">string</a></span> | <span class="param-type"><a href="function.html">function</a></span> </td> <td class="attributes"> </td> <td class="default"> </td> <td class="description last"></td> </tr> <tr> <td class="name"><code>propValue</code></td> <td class="type"> <span class="param-type">any</span> | <span class="param-type">null</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> <code>null</code> </td> <td class="description last"></td> </tr> <tr> <td class="name"><code>falseValues</code></td> <td class="type"> <span class="param-type"><a href="boolean.html">boolean</a></span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> <code>false</code> </td> <td class="description last"></td> </tr> </tbody> </table> <h5>Returns:</h5> <dl class="param-type"> <dt> Type </dt> <dd> <span class="param-type"><a href="number.html">number</a></span> </dd> </dl> <h4 class="name" id="cut"><span class="type-signature"></span>cut<span class="signature">(a)</span><span class="type-signature"> &rarr; {<a href="array.html">array</a>}</span></h4> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="Extensions_array.js.html">Extensions/array.js</a>, <a href="Extensions_array.js.html#line1300">line 1300</a> </li></ul></dd> </dl> <div class="description"> returns a sliced array with all elements but the last item </div> <h5>Example</h5> <p class="code-caption">eg. usage</p> <pre class="prettyprint"><code>var a = [1, 2, 3, 4, 5]; console.log(Array.cut(a)); // [1, 2, 3, 4] console.log(a.cut()); // same as above</code></pre> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>a</code></td> <td class="type"> <span class="param-type"><a href="array.html">array</a></span> </td> <td class="description last">the array</td> </tr> </tbody> </table> <h5>Returns:</h5> <dl class="param-type"> <dt> Type </dt> <dd> <span class="param-type"><a href="array.html">array</a></span> </dd> </dl> <h4 class="name" id="deepFindBy"><span class="type-signature"></span>deepFindBy<span class="signature">(a, propName, propValue<span class="signature-attributes">opt</span>, childrenPropName<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &rarr; {<a href="array.html">array</a>}</span></h4> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="Extensions_array.js.html">Extensions/array.js</a>, <a href="Extensions_array.js.html#line513">line 513</a> </li></ul></dd> </dl> <div class="description"> deeply sorts an array </div> <h5>Example</h5> <p class="code-caption">eg. usage</p> <pre class="prettyprint"><code>var collection = [ {type: 'b', value: 'b', items: [ {type: 'b', value: 'b-1'}, {type: 'b', value: 'b-5'}, {type: 'b', value: 'b-2'}, {type: 'b', value: 'b-4'}, {type: 'b', value: 'b-3'}, ]}, {type: 'd', value: 'd'}, {type: 'a', value: 'a', items: [ {type: 'a', value: 'a-1', items: [ {type: 'a', value: 'a-1-1'}, {type: 'a', value: 'a-1-3'}, {type: 'a', value: 'a-1-2'}, ]}}, {type: 'a', value: 'a-5', items: [ {type: 'a', value: 'a-5-1'}, ]}}, {type: 'a', value: 'a-2', items: [ {type: 'a', value: 'a-2-1'}, {type: 'a', value: 'a-2-3'}, {type: 'a', value: 'a-2-2'}, {type: 'a', value: 'a-2-4'}, ]}}, {type: 'a', value: 'a-4', items: [ {type: 'a', value: 'a-4-1'}, ]}}, {type: 'a', value: 'a-3', items: [ {type: 'a', value: 'a-3-2'}, {type: 'a', value: 'a-3-1'}, ]}}, ]}, {type: 'c', value: 'c', items: []}, ]; console.log(Array.deepFindBy(collection, 'value', 'a-2-1', 'items')); // {type: 'a', value: 'a-2-1'} console.log(collection.deepFindBy('value', 'a-2-1', 'items')); // same as above console.log(Array.deepFindBy(collection, function(item) { return item.value.contains('a-2-1'); }, null, 'items')); // {type: 'a', value: 'a-2-1'} console.log(collection.deepFindBy(function(item) { return item.value.contains('a-2-1'); }, null, 'items')); // same as above</code></pre> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Attributes</th> <th>Default</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>a</code></td> <td class="type"> <span class="param-type"><a href="array.html">array</a></span> </td> <td class="attributes"> </td> <td class="default"> </td> <td class="description last">the array</td> </tr> <tr> <td class="name"><code>propName</code></td> <td class="type"> <span class="param-type"><a href="string.html">string</a></span> | <span class="param-type"><a href="function.html">function</a></span> </td> <td class="attributes"> </td> <td class="default"> </td> <td class="description last">the propName you want to use for the deep find</td> </tr> <tr> <td class="name"><code>propValue</code></td> <td class="type"> <span class="param-type">any</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> <code>null</code> </td> <td class="description last">the propValue you want to use for the deep find</td> </tr> <tr> <td class="name"><code>childrenPropName</code></td> <td class="type"> <span class="param-type"><a href="string.html">string</a></span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> <code>'children'</code> </td> <td class="description last">the childrenPropName to be used for the deep find recursion</td> </tr> </tbody> </table> <h5>Returns:</h5> <dl class="param-type"> <dt> Type </dt> <dd> <span class="param-type"><a href="array.html">array</a></span> </dd> </dl> <h4 class="name" id="deepMap"><span class="type-signature"></span>deepMap<span class="signature">(a, childrenPropName<span class="signature-attributes">opt</span>, iteratee)</span><span class="type-signature"></span></h4> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="Extensions_array.js.html">Extensions/array.js</a>, <a href="Extensions_array.js.html#line1102">line 1102</a> </li></ul></dd> </dl> <div class="description"> deeply maps a recursive tree structure with (same structure) childrenPropName or 'children' property<br><br> <a href="lodash.html#deepMap"><code>for examples see lodash.deepMap</code></a> </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Attributes</th> <th>Default</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>a</code></td> <td class="type"> <span class="param-type"><a href="array.html">array</a></span> | <span class="param-type"><a href="object.html">object</a></span> </td> <td class="attributes"> </td> <td class="default"> </td> <td class="description last">the array to use for the deep mapping</td> </tr> <tr> <td class="name"><code>childrenPropName</code></td> <td class="type"> <span class="param-type"><a href="string.html">string</a></span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> <code>'children'</code> </td> <td class="description last">the property name to use for children collection</td> </tr> <tr> <td class="name"><code>iteratee</code></td> <td class="type"> <span class="param-type"><a href="function.html">function</a></span> </td> <td class="attributes"> </td> <td class="default"> </td> <td class="description last">the item mapping iteratee</td> </tr> </tbody> </table> <h4 class="name" id="deepSortBy"><span class="type-signature"></span>deepSortBy<span class="signature">(a, propNames, propDirections<span class="signature-attributes">opt</span>, childrenPropName<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &rarr; {<a href="array.html">array</a>}</span></h4> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="Extensions_array.js.html">Extensions/array.js</a>, <a href="Extensions_array.js.html#line236">line 236</a> </li></ul></dd> </dl> <div class="description"> deeply sorts an array </div> <h5>Example</h5> <p class="code-caption">eg. usage</p> <pre class="prettyprint"><code>var collection = [ {type: 'b', value: 'b', items: [ {type: 'b', value: 'b-1'}, {type: 'b', value: 'b-5'}, {type: 'b', value: 'b-2'}, {type: 'b', value: 'b-4'}, {type: 'b', value: 'b-3'}, ]}, {type: 'd', value: 'd'}, {type: 'a', value: 'a', items: [ {type: 'a', value: 'a-1', items: [ {type: 'a', value: 'a-1-1'}, {type: 'a', value: 'a-1-3'}, {type: 'a', value: 'a-1-2'}, ]}}, {type: 'a', value: 'a-5', items: [ {type: 'a', value: 'a-5-1'}, ]}}, {type: 'a', value: 'a-2', items: [ {type: 'a', value: 'a-2-1'}, {type: 'a', value: 'a-2-3'}, {type: 'a', value: 'a-2-2'}, {type: 'a', value: 'a-2-4'}, ]}}, {type: 'a', value: 'a-4', items: [ {type: 'a', value: 'a-4-1'}, ]}}, {type: 'a', value: 'a-3', items: [ {type: 'a', value: 'a-3-2'}, {type: 'a', value: 'a-3-1'}, ]}}, ]}, {type: 'c', value: 'c', items: []}, ]; console.log(Array.deepSortBy(collection, ['type', 'value'], ['asc', 'desc'], 'items')); // [ // {type: 'a', value: 'a', items: [ // {type: 'a', value: 'a-5', items: [ // {type: 'a', value: 'a-5-1'}, // ]}}, // {type: 'a', value: 'a-4', items: [ // {type: 'a', value: 'a-4-1'}, // ]}}, // {type: 'a', value: 'a-3', items: [ // {type: 'a', value: 'a-3-2'}, // {type: 'a', value: 'a-3-1'}, // ]}}, // {type: 'a', value: 'a-2', items: [ // {type: 'a', value: 'a-2-4'}, // {type: 'a', value: 'a-2-3'}, // {type: 'a', value: 'a-2-2'}, // {type: 'a', value: 'a-2-1'}, // ]}}, // {type: 'a', value: 'a-1', items: [ // {type: 'a', value: 'a-1-3'}, // {type: 'a', value: 'a-1-2'}, // {type: 'a', value: 'a-1-1'}, // ]}}, // ]}, // {type: 'b', value: 'b', items: [ // {type: 'b', value: 'b-5'}, // {type: 'b', value: 'b-4'}, // {type: 'b', value: 'b-3'}, // {type: 'b', value: 'b-2'}, // {type: 'b', value: 'b-1'}, // ]}, // {type: 'c', value: 'c', items: []}, // {type: 'd', value: 'd'}, // ]</code></pre> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Attributes</th> <th>Default</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>a</code></td> <td class="type"> <span class="param-type"><a href="array.html">array</a></span> </td> <td class="attributes"> </td> <td class="default"> </td> <td class="description last">the array to be sorted</td> </tr> <tr> <td class="name"><code>propNames</code></td> <td class="type"> <span class="param-type"><a href="array.html">array</a></span> | <span class="param-type"><a href="string.html">string</a></span> </td> <td class="attributes"> </td> <td class="default"> </td> <td class="description last">the propName(s) you want to use for sorting</td> </tr> <tr> <td class="name"><code>propDirections</code></td> <td class="type"> <span class="param-type"><a href="array.html">array</a></span> | <span class="param-type"><a href="string.html">string</a></span> | <span class="param-type">null</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> <code>null</code> </td> <td class="description last">the propDirection(s) you want to use for sorting (respect propName(s) order)</td> </tr> <tr> <td class="name"><code>childrenPropName</code></td> <td class="type"> <span class="param-type"><a href="string.html">string</a></span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> <code>'children'</code> </td> <td class="description last">the childrenPropName to be used for sorting</td> </tr> </tbody> </table> <h5>Returns:</h5> <dl class="param-type"> <dt> Type </dt> <dd> <span class="param-type"><a href="array.html">array</a></span> </dd> </dl> <h4 class="name" id="diff"><span class="type-signature"></span>diff<span class="signature">(a, b, fn<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &rarr; {<a href="array.html">array</a>}</span></h4> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="Extensions_array.js.html">Extensions/array.js</a>, <a href="Extensions_array.js.html#line101">line 101</a> </li></ul></dd> </dl> <div class="description"> creates an array of unique array values not included in the other provided arrays </div> <h5>Example</h5> <p class="code-caption">eg. usage</p> <pre class="prettyprint"><code>var arr = ['a', 'e', 'i', 'o', 'u']; var arr2 = ['a', 'b', 'c', 'd', 'e']; console.log(Array.diff(arr, arr2)); // ['i', 'o', 'u'] console.log(arr.diff(arr2)); // same as above console.log(Array.diff(arr2, arr)); // ['b', 'c', 'd'] console.log(arr2.diff(arr)); // same as above var collection = [{id: 1, type: 'a'}, {id: 2, type: 'e'}, {id: 3, type: 'i'}, {id: 4, type: 'o'}, {id: 5, type: 'u'}]; var collection2 = [{id: 1, type: 'a'}, {id: 2, type: 'b'}, {id: 3, type: 'c'}, {id: 4, type: 'd'}, {id: 5, type: 'e'}]; console.log(Array.diff(collection, collection2)); // [{id: 2, type: 'e'}, {id: 3, type: 'i'}, {id: 4, type: 'o'}, {id: 5, type: 'u'}] console.log(collection.diff(collection2)); // same as above console.log(Array.diff(collection, collection2, 'type'); // [{id: 3, type: 'i'}, {id: 4, type: 'o'}, {id: 5, type: 'u'}] console.log(collection.diff(collection2, 'type'); // same as above console.log(Array.diff(collection, collection2, function(aitem, bitem) { return aitem.type === bitem.type; })); // same as above console.log(collection.diff(collection2, function(aitem, bitem) { return aitem.type === bitem.type; })); // same as above</code></pre> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Attributes</th> <th>Default</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>a</code></td> <td class="type"> <span class="param-type"><a href="array.html">array</a></span> </td> <td class="attributes"> </td> <td class="default"> </td> <td class="description last">the first array to use for the diff</td> </tr> <tr> <td class="name"><code>b</code></td> <td class="type">