Created
February 12, 2020 11:27
-
-
Save whitehorse0/275baae4294849d0a89204f5f5d02e38 to your computer and use it in GitHub Desktop.
helper function common used
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
getNestedObject: (nestedObj, pathArr) => { | |
return pathArr.reduce((obj, key) => (obj && obj[key] !== 'undefined') ? obj[key] : undefined, nestedObj) | |
}, | |
extendObject: (accumulator, currentValue) => { | |
for (var p in currentValue) { | |
try { | |
if (currentValue[p].constructor == Object) { | |
accumulator[p] = _helper.extendObject(accumulator[p], currentValue[p]) | |
} else { | |
accumulator[p] = currentValue[p] | |
} | |
} catch (e) { | |
console.error(e) | |
accumulator[p] = currentValue[p] | |
} | |
} | |
return accumulator | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment