- diff: function(left, right, minimal, key) {
- /* Build a diff between the structures left and right.
-
- Parameters:
- key: this is used for mutual recursion between this
- function and those it calls. Normally it should be
- left unset or set as its default [].
-
- minimal: if this flag is set true, the function will try
- harder to find the diff that encodes as the shortest
- possible JSON string, at the expense of using more of
- both memory and processor time (as alternatives are
- computed and compared).
- */
- key = key !== undefined ? key : [];
- minimal = minimal !== undefined ? minimal : true;
- var dumbdiff = [[key, right]], my_diff = [], common;
-
- if (this.structureWorthInvestigating(left, right)) {
- common = this.commonality(left, right);
- if (minimal) {
- my_diff = this.needleDiff(left, right, minimal, key);
- } else if (common < 0.5) {
- my_diff = this.thisLevelDiff(left, right, key, common);
- } else {
- my_diff = this.keysetDiff(left, right, minimal, key);
- }
- } else {
- my_diff = this.thisLevelDiff(left, right, key, 0.0);