UNPKG

732 BJavaScriptView Raw
1/*jshint indent:2, laxcomma:true, laxbreak:true*/
2var util = require('util')
3, diff = require('..')
4, data = require('./practice-data')
5;
6
7var cycle = -1
8, i
9, len = data.length
10, prior = {}
11, comparand
12, records
13, ch
14;
15
16var applyEachChange = function (ch) {
17 diff.applyChange(prior, comparand, ch);
18 };
19
20while (++cycle < 10) {
21 i = -1;
22 while (++i < len) {
23
24 comparand = data[i];
25
26 // get the difference...
27 records = diff(prior, comparand);
28
29 // round-trip serialize to prune the underlying types...
30 var serialized = JSON.stringify(records);
31 var desierialized = JSON.parse(serialized);
32
33 if (desierialized) {
34 desierialized.forEach(applyEachChange);
35
36 prior = comparand;
37 }
38 }
39}