Travis build: 875

This commit is contained in:
30secondsofcode
2018-12-10 09:53:13 +00:00
parent 769511681d
commit beab8661a5
18 changed files with 141 additions and 31 deletions

View File

@ -363,6 +363,7 @@ _30s.average(1, 2, 3);
* [`bindAll`](#bindall)
* [`deepClone`](#deepclone)
* [`deepFreeze`](#deepfreeze)
* [`deepMapKeys`](#deepmapkeys-)
* [`defaults`](#defaults)
* [`dig`](#dig)
* [`equals`](#equals-)
@ -6707,6 +6708,66 @@ o[1][0] = 4; // not allowed as well
<br>[⬆ Back to top](#contents)
### deepMapKeys ![advanced](/advanced.svg)
Deep maps an object keys.
Creates an object with the same values as the provided object and keys generated by running the provided function for each key.
Use `Object.keys(obj)` to iterate over the object's keys.
Use `Array.prototype.reduce()` to create a new object with the same values and mapped keys using `fn`.
```js
const deepMapKeys = (obj, f) =>
Array.isArray(obj)
? obj.map(val => deepMapKeys(val, f))
: typeof obj === 'object'
? Object.keys(obj).reduce((acc, current) => {
const val = obj[current];
acc[f(current)] =
val !== null && typeof val === 'object' ? deepMapKeys(val, f) : (acc[f(current)] = val);
return acc;
}, {})
: obj;
```
<details>
<summary>Examples</summary>
```js
const obj = {
foo: '1',
nested: {
child: {
withArray: [
{
grandChild: ['hello']
}
]
}
}
};
const upperKeysObj = deepMapKeys(obj, key => key.toUpperCase());
/*
{
"FOO":"1",
"NESTED":{
"CHILD":{
"WITHARRAY":[
{
"GRANDCHILD":[ 'hello' ]
}
]
}
}
}
*/
```
</details>
<br>[⬆ Back to top](#contents)
### defaults
Assigns default values for all properties in an object that are `undefined`.