Travis build: 1340
This commit is contained in:
63
README.md
63
README.md
@ -274,6 +274,8 @@ average(1, 2, 3);
|
|||||||
|
|
||||||
* [`defaults`](#defaults)
|
* [`defaults`](#defaults)
|
||||||
* [`equals`](#equals-)
|
* [`equals`](#equals-)
|
||||||
|
* [`findKey`](#findkey)
|
||||||
|
* [`findLastKey`](#findlastkey)
|
||||||
* [`forOwn`](#forown)
|
* [`forOwn`](#forown)
|
||||||
* [`forOwnRight`](#forownright)
|
* [`forOwnRight`](#forownright)
|
||||||
* [`functions`](#functions)
|
* [`functions`](#functions)
|
||||||
@ -4240,6 +4242,67 @@ equals({ a: [2, { e: 3 }], b: [4], c: 'foo' }, { a: [2, { e: 3 }], b: [4], c: 'f
|
|||||||
<br>[⬆ Back to top](#table-of-contents)
|
<br>[⬆ Back to top](#table-of-contents)
|
||||||
|
|
||||||
|
|
||||||
|
### findKey
|
||||||
|
|
||||||
|
Returns the first key that satisfies the provided testing function. Otherwise `undefined` is returned.
|
||||||
|
|
||||||
|
Use `Object.keys(obj)` to get all the properties of the object, `Array.find()` to test the provided function for each key-value pair. The callback receives three arguments - the value, the key and the object.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const findKey = (obj, fn) => Object.keys(obj).find(key => fn(obj[key], key, obj));
|
||||||
|
```
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>Examples</summary>
|
||||||
|
|
||||||
|
```js
|
||||||
|
findKey(
|
||||||
|
{
|
||||||
|
barney: { age: 36, active: true },
|
||||||
|
fred: { age: 40, active: false },
|
||||||
|
pebbles: { age: 1, active: true }
|
||||||
|
},
|
||||||
|
o => o['active']
|
||||||
|
); // 'barney'
|
||||||
|
```
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<br>[⬆ Back to top](#table-of-contents)
|
||||||
|
|
||||||
|
|
||||||
|
### findLastKey
|
||||||
|
|
||||||
|
Returns the last key that satisfies the provided testing function. Otherwise `undefined` is returned.
|
||||||
|
|
||||||
|
Use `Object.keys(obj)` to get all the properties of the object, `Array.reverse()` to reverse their order and `Array.find()` to test the provided function for each key-value pair. The callback receives three arguments - the value, the key and the object.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const findLastKey = (obj, fn) =>
|
||||||
|
Object.keys(obj)
|
||||||
|
.reverse()
|
||||||
|
.find(key => fn(obj[key], key, obj));
|
||||||
|
```
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>Examples</summary>
|
||||||
|
|
||||||
|
```js
|
||||||
|
findLastKey(
|
||||||
|
{
|
||||||
|
barney: { age: 36, active: true },
|
||||||
|
fred: { age: 40, active: false },
|
||||||
|
pebbles: { age: 1, active: true }
|
||||||
|
},
|
||||||
|
o => o['active']
|
||||||
|
); // 'pebbles'
|
||||||
|
```
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<br>[⬆ Back to top](#table-of-contents)
|
||||||
|
|
||||||
|
|
||||||
### forOwn
|
### forOwn
|
||||||
|
|
||||||
Iterates over all own properties of an object, running a callback for each one.
|
Iterates over all own properties of an object, running a callback for each one.
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@ -5,10 +5,16 @@ Returns the first key that satisfies the provided testing function. Otherwise `u
|
|||||||
Use `Object.keys(obj)` to get all the properties of the object, `Array.find()` to test the provided function for each key-value pair. The callback receives three arguments - the value, the key and the object.
|
Use `Object.keys(obj)` to get all the properties of the object, `Array.find()` to test the provided function for each key-value pair. The callback receives three arguments - the value, the key and the object.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const findKey = (obj, fn) =>
|
const findKey = (obj, fn) => Object.keys(obj).find(key => fn(obj[key], key, obj));
|
||||||
Object.keys(obj).find(key => fn(obj[key], key, obj));
|
|
||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
findKey({barney: { age: 36, active: true }, fred: { age: 40, active: false }, pebbles: { age: 1, active: true }}, o => o['active']); // 'barney'
|
findKey(
|
||||||
|
{
|
||||||
|
barney: { age: 36, active: true },
|
||||||
|
fred: { age: 40, active: false },
|
||||||
|
pebbles: { age: 1, active: true }
|
||||||
|
},
|
||||||
|
o => o['active']
|
||||||
|
); // 'barney'
|
||||||
```
|
```
|
||||||
|
|||||||
@ -6,9 +6,18 @@ Use `Object.keys(obj)` to get all the properties of the object, `Array.reverse()
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
const findLastKey = (obj, fn) =>
|
const findLastKey = (obj, fn) =>
|
||||||
Object.keys(obj).reverse().find(key => fn(obj[key], key, obj));
|
Object.keys(obj)
|
||||||
|
.reverse()
|
||||||
|
.find(key => fn(obj[key], key, obj));
|
||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
findLastKey({barney: { age: 36, active: true }, fred: { age: 40, active: false }, pebbles: { age: 1, active: true }}, o => o['active']); // 'pebbles'
|
findLastKey(
|
||||||
|
{
|
||||||
|
barney: { age: 36, active: true },
|
||||||
|
fred: { age: 40, active: false },
|
||||||
|
pebbles: { age: 1, active: true }
|
||||||
|
},
|
||||||
|
o => o['active']
|
||||||
|
); // 'pebbles'
|
||||||
```
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user