Skip to content

Instantly share code, notes, and snippets.

@dmitryshimkin
Last active October 28, 2015 11:44
Show Gist options
  • Select an option

  • Save dmitryshimkin/1363d8d1d3b98f184da3 to your computer and use it in GitHub Desktop.

Select an option

Save dmitryshimkin/1363d8d1d3b98f184da3 to your computer and use it in GitHub Desktop.
function getAverage (arr) {
return arr.reduce(function (prev, cur) {
return prev + cur;
}) / arr.length;
}
function getNestedLevel (el) {
var level = 0;
while (el = el.parentNode) {
level++;
}
return level;
}
function getAverageDomDepth () {
var all = [].slice.call(document.querySelectorAll('*'));
var levels = all.map(function (el) {
return getNestedLevel(el);
});
return getAverage(levels);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment