Skip to content

Instantly share code, notes, and snippets.

@bebraw
Created December 29, 2010 15:45
Show Gist options
  • Save bebraw/758651 to your computer and use it in GitHub Desktop.
Save bebraw/758651 to your computer and use it in GitHub Desktop.
// original
for(e,l='article aside footer header nav section time'.split(' ');e=l.pop();document.createElement(e))
// original + moved pop
for(l='article aside footer header nav section time'.split(' ');;document.createElement(l.pop()))
// mine (not tested! might need some braces...)
// v1 (no globals)
var l=['article','aside','footer','header','nav','section','time'];for(var i in l)document.createElement(l[i])
// v2 (globals)
l=['article','aside','footer','header','nav','section','time'];for(i in l)document.createElement(l[i])
@hagenburger
Copy link

in returns the index, so it would result in 0, 1, 2, …

@bebraw
Copy link
Author

bebraw commented Dec 29, 2010

I think the last version is about as compact as I can get. Saves a few chars. Not sure if it's worth it, though...

@hagenburger
Copy link

For v1 l will also be in the global scope. For me, the new scope created by for is worth it :)

Btw. the split version is even a bit smaller, especially if you add more HTML5 elements.

@bebraw
Copy link
Author

bebraw commented Dec 29, 2010

True. Just figured out you can probably refactor "e" out of the original version. Just pop at createElement.

@hagenburger
Copy link

You may want to avoid endless loops.

@bebraw
Copy link
Author

bebraw commented Dec 29, 2010

Oh. Gotcha! Man, I need to test these things... :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment