Build
This commit is contained in:
@ -154,6 +154,7 @@
|
||||
</h3><a class="sublink-1" href="#cleanobj">cleanObj</a>
|
||||
<a class="sublink-1" href="#objectfrompairs">objectFromPairs</a>
|
||||
<a class="sublink-1" href="#objecttopairs">objectToPairs</a>
|
||||
<a class="sublink-1" href="#orderby">orderBy</a>
|
||||
<a class="sublink-1" href="#select">select</a>
|
||||
<a class="sublink-1" href="#shallowclone">shallowClone</a>
|
||||
<a class="sublink-1" href="#truthcheckcollection">truthCheckCollection</a>
|
||||
@ -964,6 +965,27 @@ Also if you give it a special key (<code>childIndicator</code>) it will search d
|
||||
<pre><code class="language-js">const objectToPairs = obj => Object.keys(obj).map(k => [k, obj[k]]);
|
||||
// objectToPairs({a: 1, b: 2}) -> [['a',1],['b',2]])
|
||||
</code></pre>
|
||||
</div></div><br/><div class="card fluid"><div class="section double-padded"><h3 id="orderby">orderBy</h3></div><div class="section double-padded">
|
||||
<p>Returns a sorted array of objects ordered by properties and orders.</p>
|
||||
<p>Uses a custom implementation of sort, that reduces the props array argument with a default value of 0, it uses destructuring to swap the properties position depending on the order passed.
|
||||
If no orders array is passed it sort by 'asc' by default.</p>
|
||||
<pre><code class="language-js">const orderBy = (arr, props, orders) =>
|
||||
arr.sort((a, b) =>
|
||||
props.reduce((acc, prop, i) => {
|
||||
if (acc === 0) {
|
||||
const [p1, p2] = orders[i] === 'asc' ? [a[prop], b[prop]] : [b[prop], a[prop]];
|
||||
acc = p1 > p2 ? 1 : p1 < p2 ? -1 : 0;
|
||||
}
|
||||
return acc;
|
||||
}, 0)
|
||||
);
|
||||
/*
|
||||
const users = [{ 'name': 'fred', 'age': 48 },{ 'name': 'barney', 'age': 36 },
|
||||
{ 'name': 'fred', 'age': 40 },{ 'name': 'barney', 'age': 34 }];
|
||||
orderby(users, ['name', 'age'], ['asc', 'desc']) -> [{name: 'barney', age: 36}, {name: 'barney', age: 34}, {name: 'fred', age: 48}, {name: 'fred', age: 40}]
|
||||
orderby(users, ['name', 'age']) -> [{name: 'barney', age: 34}, {name: 'barney', age: 36}, {name: 'fred', age: 40}, {name: 'fred', age: 48}]
|
||||
*/
|
||||
</code></pre>
|
||||
</div></div><br/><div class="card fluid"><div class="section double-padded"><h3 id="select">select</h3></div><div class="section double-padded">
|
||||
<p>Retrieve a property that indicated by the selector from object.</p>
|
||||
<p>If property not exists returns <code>undefined</code>.</p>
|
||||
|
||||
Reference in New Issue
Block a user