Last active
December 26, 2018 16:52
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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