Travis build: 2112

This commit is contained in:
30secondsofcode
2018-05-31 18:27:05 +00:00
parent 4eba8103ea
commit 41f0078709
12 changed files with 70 additions and 61 deletions

View File

@@ -175,6 +175,7 @@ average(1, 2, 3);
* [`takeRight`](#takeright)
* [`takeRightWhile`](#takerightwhile)
* [`takeWhile`](#takewhile)
* [`toHash`](#tohash)
* [`union`](#union)
* [`unionBy`](#unionby)
* [`unionWith`](#unionwith)
@@ -470,15 +471,6 @@ average(1, 2, 3);
</details>
### Uncategorized
<details>
<summary>View contents</summary>
* [`toHash`](#tohash)
</details>
---
## 🔌 Adapter
@@ -2701,6 +2693,45 @@ takeWhile([1, 2, 3, 4], n => n >= 3); // [1, 2]
<br>[⬆ Back to top](#table-of-contents)
### 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)
### union
Returns every element that exists in any of the two arrays once.
@@ -8918,47 +8949,6 @@ 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