Skip to content

Instantly share code, notes, and snippets.

@craigrbruce
Created July 7, 2016 05:38
Show Gist options
  • Save craigrbruce/c18a1ef69f9d1f07754ab580bac974c7 to your computer and use it in GitHub Desktop.
Save craigrbruce/c18a1ef69f9d1f07754ab580bac974c7 to your computer and use it in GitHub Desktop.
Object property dirty checker with dependency on lodash
/**
* Checks all fields of an object literal for values.
* @param {Object} object - A POJO.
* @param {Array<String>} omitProperies - An array of properties that you wish to omit from the checker e.g. "id".
* @returns {Boolean}
*/
function isObjectDirty(object, omitProperties) {
if(omitProperties) {
object = _.omit(object, omitProperties);
}
return _.some(_.values(object), (value) => {
if (_.isArray(value)) {
return _.some(value, (item) => isObjectDirty(item, omitProperties));
}
if (_.isPlainObject(value)) {
return isObjectDirty(value, omitProperties);
}
return !!value
});
}
@FahmyChaabane
Copy link

Hi,
For learning purposes.. what's the diff between using your method VS simply stringifying two objects and use the === operator in js ?
Thank u in advance :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment