Travis build: 2110

This commit is contained in:
30secondsofcode
2018-05-31 18:13:03 +00:00
parent 73b905c42e
commit 8e1c3ef934
15 changed files with 177 additions and 23 deletions

View File

@ -470,6 +470,15 @@ average(1, 2, 3);
</details>
### Uncategorized
<details>
<summary>View contents</summary>
* [`toHash`](#tohash)
</details>
---
## 🔌 Adapter
@ -8909,6 +8918,47 @@ yesNo('Foo', true); // true
<br>[⬆ Back to top](#table-of-contents)
---
## Uncategorized
### toHash
Reduces a given Array-like into a value hash (keyed data store).
Given an Iterable or Array-like structure, call `Array.prototype.reduce.call()` on the provided object to step over it and return an Object, keyed by the reference value.
```js
const toHash = (object, key) =>
Array.prototype.reduce.call(
object,
(acc, data, index) => ((acc[!key ? index : data[key]] = data), acc),
{}
);
```
<details>
<summary>Examples</summary>
```js
toHash([4, 3, 2, 1]); // { 0: 4, 1: 3, 2: 2, 1: 1 }
toHash([{ a: 'label' }], 'a'); // { label: { a: 'label' } }
// A more in depth example:
let users = [{ id: 1, first: 'Jon' }, { id: 2, first: 'Joe' }, { id: 3, first: 'Moe' }];
let managers = [{ manager: 1, employees: [2, 3] }];
// We use function here because we want a bindable reference, but a closure referencing the hash would work, too.
managers.forEach(
manager =>
(manager.employees = manager.employees.map(function(id) {
return this[id];
}, toHash(users, 'id')))
);
managers; // [ { manager:1, employees: [ { id: 2, first: "Joe" }, { id: 3, first: "Moe" } ] } ]
```
</details>
<br>[⬆ Back to top](#table-of-contents)
## Collaborators

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

101
docs/uncategorized.html Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -5,24 +5,26 @@ Reduces a given Array-like into a value hash (keyed data store).
Given an Iterable or Array-like structure, call `Array.prototype.reduce.call()` on the provided object to step over it and return an Object, keyed by the reference value.
```js
const toHash = ( object, key ) =>
Array.prototype.reduce.call( object, ( acc, data, index ) => ( ( acc[ !key ? index : data[ key ] ] = data ), acc ), {} )
const toHash = (object, key) =>
Array.prototype.reduce.call(
object,
(acc, data, index) => ((acc[!key ? index : data[key]] = data), acc),
{}
);
```
```js
toHash([ 4,3,2,1 ]); // { 0: 4, 1: 3, 2: 2, 1: 1 }
toHash([ { a: 'label' } ], 'a'); // { label: { a: 'label' } }
toHash([4, 3, 2, 1]); // { 0: 4, 1: 3, 2: 2, 1: 1 }
toHash([{ a: 'label' }], 'a'); // { label: { a: 'label' } }
// A more in depth example:
let users = [ { id: 1, first: 'Jon' }, { id: 2, first: 'Joe' }, { id: 3, first: 'Moe' } ];
let managers = [ { manager: 1, employees: [ 2, 3 ] } ];
let users = [{ id: 1, first: 'Jon' }, { id: 2, first: 'Joe' }, { id: 3, first: 'Moe' }];
let managers = [{ manager: 1, employees: [2, 3] }];
// We use function here because we want a bindable reference, but a closure referencing the hash would work, too.
managers.forEach( manager =>
manager.employees = manager.employees.map(
function( id ){
managers.forEach(
manager =>
(manager.employees = manager.employees.map(function(id) {
return this[id];
},
toHash( users, 'id' )
)
}, toHash(users, 'id')))
);
managers; // [ { manager:1, employees: [ { id: 2, first: "Joe" }, { id: 3, first: "Moe" } ] } ]
```

View File

@ -270,6 +270,7 @@ toCamelCase:string,regexp
toCurrency:utility
toDecimalMark:utility,math
toggleClass:browser
toHash:uncategorized
toKebabCase:string,regexp
tomorrow:date
toOrdinalSuffix:utility,math