Skip to content

Instantly share code, notes, and snippets.

@kevinmarks
Last active December 26, 2018 16:52
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevinmarks/dd62a4b96b4ad5b2e1dc1f8665322921 to your computer and use it in GitHub Desktop.
Save kevinmarks/dd62a4b96b4ad5b2e1dc1f8665322921 to your computer and use it in GitHub Desktop.
Diff data stripped - compare objects and show only the inner bits that differ
function diffdatastripped(legacy,shiny) {
let delta={},allgood=true;
for (const key in legacy){
const oldval = legacy[key];
const newval = shiny[key];
if (typeof(oldval)==='object' && typeof(newval)==='object'){
delta[key] = diffdatastripped(oldval,newval)
if (delta[key] !="✅") {
allgood=false;
}
} else if (oldval==newval){
delta[key]="✅";
} else if(Math.abs((oldval-newval)/oldval)<0.005){
delta[key]="≅";
} else {
delta[key]="❌ expected: "+oldval+" got: "+newval;
allgood=false;
}
}
if (allgood){
return "✅";
} else {
return delta;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment