Skip to content

Instantly share code, notes, and snippets.

@matt-auckland
Last active November 18, 2019 01:37
Show Gist options
  • Save matt-auckland/e897c140bbe8ecdea0e7166b5041feb7 to your computer and use it in GitHub Desktop.
Save matt-auckland/e897c140bbe8ecdea0e7166b5041feb7 to your computer and use it in GitHub Desktop.
Count nodes
var maxDepth = 0;
const boop = function (boopName = '#app') {
maxDepth = 0;
var parent = document.querySelector(boopName);
console.log(dig(parent, 0, maxDepth));
console.log(`max depth found: ${maxDepth}`);
}
const dig = function (parent, currentDepth) {
let count = 1;
if (parent.childNodes && parent.childNodes.length > 60) {
console.log('excessive number of childNodes (> 60) for parent=');
console.log(parent);
}
if (currentDepth > maxDepth) {
maxDepth = currentDepth;
}
_.each(parent.childNodes, function (child) {
if (child && child.childNodes.length > 0) {
count += dig(child, currentDepth + 1);
}
});
return count;
}
COMMONUTILS.logTime= function (label) {
console.log(`${label}: ${performance.now() - window.timeRecord}`)
}
COMMONUTILS.recordTime= function (label, time) {
console.log(`${label}: ${performance.now() - time}`)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment