Last active
October 28, 2015 11:44
-
-
Save dmitryshimkin/1363d8d1d3b98f184da3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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