Created
December 8, 2021 23:52
-
-
Save monkpit/9808b9f9f0a6e62367bd0398eee5d3d9 to your computer and use it in GitHub Desktop.
Merge two objects (not recursive), but only keep properties that already exist on the target object.
This file contains hidden or 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
const R = require('ramda'); | |
const mergeExistingProps = (target, updater) => { | |
const targetClone = R.clone(target); | |
for (const prop in targetClone) { | |
if (Object.prototype.hasOwnProperty.call(updater, prop)) { | |
targetClone[prop] = updater[prop]; | |
} | |
} | |
return targetClone; | |
}; | |
module.exports = mergeExistingProps; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Open to ideas of how to make this recursive but also readable 😆 not sure how to quickly check if
updater[prop]
should trigger recursion.