Travis build: 1905
This commit is contained in:
@ -1436,7 +1436,7 @@
|
|||||||
"fileName": "deepMapKeys.md",
|
"fileName": "deepMapKeys.md",
|
||||||
"text": "Deep maps an object's keys.\n\nCreates an object with the same values as the provided object and keys generated by running the provided function for each key.\nUse `Object.keys(obj)` to iterate over the object's keys.\nUse `Array.prototype.reduce()` to create a new object with the same values and mapped keys using `fn`.\n\n",
|
"text": "Deep maps an object's keys.\n\nCreates an object with the same values as the provided object and keys generated by running the provided function for each key.\nUse `Object.keys(obj)` to iterate over the object's keys.\nUse `Array.prototype.reduce()` to create a new object with the same values and mapped keys using `fn`.\n\n",
|
||||||
"codeBlocks": {
|
"codeBlocks": {
|
||||||
"code": "const deepMapKeys = (obj, f) =>\n Array.isArray(obj)\n ? obj.map(val => deepMapKeys(val, f))\n : typeof obj === 'object'\n ? Object.keys(obj).reduce((acc, current) => {\n const val = obj[current];\n acc[f(current)] =\n val !== null && typeof val === 'object' ? deepMapKeys(val, f) : (acc[f(current)] = val);\n return acc;\n }, {})\n : obj;",
|
"code": "const deepMapKeys = (obj, fn) =>\n Array.isArray(obj)\n ? obj.map(val => deepMapKeys(val, fn))\n : typeof obj === 'object'\n ? Object.keys(obj).reduce((acc, current) => {\n const key = fn(current);\n const val = obj[current];\n acc[key] =\n val !== null && typeof val === 'object' ? deepMapKeys(val, fn) : val;\n return acc;\n }, {})\n : obj;",
|
||||||
"example": "const obj = {\n foo: '1',\n nested: {\n child: {\n withArray: [\n {\n grandChild: ['hello']\n }\n ]\n }\n }\n};\nconst upperKeysObj = deepMapKeys(obj, key => key.toUpperCase());\n/*\n{\n \"FOO\":\"1\",\n \"NESTED\":{\n \"CHILD\":{\n \"WITHARRAY\":[\n {\n \"GRANDCHILD\":[ 'hello' ]\n }\n ]\n }\n }\n}\n*/"
|
"example": "const obj = {\n foo: '1',\n nested: {\n child: {\n withArray: [\n {\n grandChild: ['hello']\n }\n ]\n }\n }\n};\nconst upperKeysObj = deepMapKeys(obj, key => key.toUpperCase());\n/*\n{\n \"FOO\":\"1\",\n \"NESTED\":{\n \"CHILD\":{\n \"WITHARRAY\":[\n {\n \"GRANDCHILD\":[ 'hello' ]\n }\n ]\n }\n }\n}\n*/"
|
||||||
},
|
},
|
||||||
"tags": [
|
"tags": [
|
||||||
@ -1446,10 +1446,10 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"meta": {
|
"meta": {
|
||||||
"hash": "a4e1e33c0688dbf1ca231d9d8ea315ffed93b7f83f5d8cbf0714f10fdfeda8cf",
|
"hash": "49d6a6279af3abfd3e63af21edaabc7137bef4b729102c08d333c8a423591edc",
|
||||||
"firstSeen": "1544374334",
|
"firstSeen": "1544374334",
|
||||||
"lastUpdated": "1587068503",
|
"lastUpdated": "1587369956",
|
||||||
"updateCount": 102,
|
"updateCount": 103,
|
||||||
"authorCount": 4
|
"authorCount": 4
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user