Skip to content

Instantly share code, notes, and snippets.

@rodrigobdz
Created May 9, 2018 13:09
Show Gist options
  • Save rodrigobdz/f505fe4cb20a79a9b82fa62383b1149b to your computer and use it in GitHub Desktop.
Save rodrigobdz/f505fe4cb20a79a9b82fa62383b1149b to your computer and use it in GitHub Desktop.
/**
* Update values only for existing keys
* @param {Object} outdated Object with old values
* @param {Object} updated Object with updated values, it may have unnecessary keys.
*/
const updateExistingProperties = (outdated, updated) => {
var result = {...outdated}
for (let k of Object.keys(updated)) {
// Ignore unnecessary keys
if (!(k in result)) {
continue
}
result[k] = updated[k]
}
return result
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment