Skip to content

Instantly share code, notes, and snippets.

@lsongdev
Created October 19, 2016 14:52
Show Gist options
  • Select an option

  • Save lsongdev/d48d8481195befa3e4c05854224ed41f to your computer and use it in GitHub Desktop.

Select an option

Save lsongdev/d48d8481195befa3e4c05854224ed41f to your computer and use it in GitHub Desktop.
function (
a, // A Nodelist whichto use as root
b, // iterate-placeholder
c, // elem-placeholder
d, // tags-placeholder
e, // tag-placeholder
f // parent-placeholder
) {
for (b = 0; c = a[b++];
// parent has already the same `tagName` as property
// so there is more than one element in the tree
(f = c.parentNode)[e] && f[d].push(c) ||
// otherwise add/assign an array
// containing the element
(f[d] = [c]),
// assign the single node to the parent-node
f[e] = c)
d = (e = c.tagName.toLowerCase()) + 's'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment