Skip to content

Instantly share code, notes, and snippets.

@Constaline
Forked from Yimiprod/difference.js
Created May 7, 2019 00:30
Show Gist options
  • Save Constaline/1b973e84988f50772250feb076dec7a7 to your computer and use it in GitHub Desktop.
Save Constaline/1b973e84988f50772250feb076dec7a7 to your computer and use it in GitHub Desktop.

Revisions

  1. @Yimiprod Yimiprod revised this gist Sep 16, 2015. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions difference.js
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,8 @@
    /**
    * Deep diff between two object, using lodash
    * @param {Object} object Object compared
    * @param {Object} base Object to compare with
    * @return {Object} Return a new object containing the diff
    * @param {Object} base Object to compare with
    * @return {Object} Return a new object who represent the diff
    */
    function difference(object, base) {
    function changes(object, base) {
  2. @Yimiprod Yimiprod created this gist Sep 1, 2015.
    16 changes: 16 additions & 0 deletions difference.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    /**
    * Deep diff between two object, using lodash
    * @param {Object} object Object compared
    * @param {Object} base Object to compare with
    * @return {Object} Return a new object containing the diff
    */
    function difference(object, base) {
    function changes(object, base) {
    return _.transform(object, function(result, value, key) {
    if (!_.isEqual(value, base[key])) {
    result[key] = (_.isObject(value) && _.isObject(base[key])) ? changes(value, base[key]) : value;
    }
    });
    }
    return changes(object, base);
    }