Skip to content

Instantly share code, notes, and snippets.

@jeremyckahn
Created April 24, 2019 15:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeremyckahn/40d6282e7bb329d42ec25c849e9dd297 to your computer and use it in GitHub Desktop.
Save jeremyckahn/40d6282e7bb329d42ec25c849e9dd297 to your computer and use it in GitHub Desktop.
Compute keys that are different between two JS objects
/**
* @param {Object} oldData
* @param {Object} newData
* @returns {Array.<string>} A list of key names that are different between
* oldData and newData.
*/
export const getChangedProperties = (oldData, newData) =>
Object.keys(oldData).reduce(
(acc, key) => (oldData[key] !== newData[key] ? [...acc, key] : acc),
[]
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment