Skip to content

Instantly share code, notes, and snippets.

@fedeghe
Last active May 1, 2019 19:34
Show Gist options
  • Save fedeghe/337fec1eb1633188087511ae78439862 to your computer and use it in GitHub Desktop.
Save fedeghe/337fec1eb1633188087511ae78439862 to your computer and use it in GitHub Desktop.
spot duplicate ids
(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