Last active
May 1, 2019 19:34
-
-
Save fedeghe/337fec1eb1633188087511ae78439862 to your computer and use it in GitHub Desktop.
spot duplicate ids
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 (idsEls) { | |
var ids = idsEls.map(e => e.id).sort(), | |
uniq = [], | |
dups = {}; | |
ids.forEach(id => { | |
if (uniq.indexOf(id) === -1) { | |
uniq.push(id); | |
} else { | |
dups[id] = id in dups ? ++dups[id] : 2; | |
} | |
}); | |
console.log(`All ids count: ${ids.length}\nUnique ones: ${uniq.length}\nDuplicates: ${JSON.stringify(dups, null, 4)}`); | |
})([].slice.call(document.querySelectorAll('[id]'), 0)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment