/*
iterate over the master object. This is the source of truth for keys
the values Master are the datatypes. Check if the value of the example match those datatypes OR are null.
recurse into the subkeys
extrakeys shows the entries that are not in the other. ⚠️ EXAMPLE.extraKeys should be empty!
badValues shows the entries that do not match the datatype. again EXAMPLE.badValues should be empty
repeate in the reverse direction -- iterating over the EXAMPLE object
*/
console.clear();
(function(EXAMPLE, MASTER) {
const summary = {};
summary.EXAMPLE = Object.assign({}, {
extraKeys: [],
badValues: [],
nulledValues : []
});
summary.MASTER = Object.assign({}, {
extraKeys: [],
badValues: [],
nulledValues : []
});
/**
CANDIDATE : { object : EXAMPLE , summary : summary.EXAMPLE}
*/
function analyzeObjects(CANDIDATE, STANDARD, flipped = false) {
let candidateObj = CANDIDATE.object;
let standardObj = STANDARD.object;
let candidateSummary = CANDIDATE.summary;
let standardSummary = STANDARD.summary;
//loop through the master object
for (let [key, dataTypeOrValue] of Object.entries(standardObj)) {
let candidateValue = candidateObj[key];
//if both are objects in recurse
if (typeof dataTypeOrValue === 'object'
&& typeof candidateValue === 'object'
&& dataTypeOrValue !== null
&& candidateValue !== null)
//recurse
// console.log('recursion should happen here');
analyzeObjects({
object: candidateObj[key],
summary: candidateSummary
}, {
object: standardObj[key],
summary: standardSummary
},
flipped
);
else if (( typeof dataTypeOrValue === 'object' && candidateValue === null && !flipped))
candidateSummary.nulledValues.push([key, typeof dataTypeOrValue ])
//if only the datatype-supplying object is an object
// else if...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.