Skip to content

Instantly share code, notes, and snippets.

@jankeromnes
Forked from espadrine/color-cheat-golf.js
Last active January 3, 2016 18:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jankeromnes/8506050 to your computer and use it in GitHub Desktop.
Save jankeromnes/8506050 to your computer and use it in GitHub Desktop.
for(i=0;++i<5;)for(j=2;++j<22;)eval('a=patch_'+i+'_'+j).parentNode.appendChild(a)
var containers = [1,2,3,4].map(n => document.getElementById('draggable_row_container_' + n));
function compare(a, b) {
return +a.id.split('_')[2] - b.id.split('_')[2];
}
function fixContainer(c) {
var children = Array.prototype.filter.call(c.childNodes, a => !!a.id);
children.sort(compare);
c.innerHTML = children.map(child => child.outerHTML).join(' ');
}
containers.forEach(c => fixContainer(c));
for(i=0;++i<5;)for(j=2;j<22;j+=(j<12?11:-10))eval('a=patch_'+i+'_'+j).parentNode.appendChild(a)
var containers = [1,2,3,4].map(n => document.getElementById('draggable_row_container_' + n));
function compare(a, b) {
return +b.id.split('_')[2] - a.id.split('_')[2];
}
function worst(l) {
var nl = [];
var halfl = l.slice(0, (l.length / 2)|0).reverse();
var rest = l.slice(halfl.length).reverse();
for (var i = 0; i < halfl.length; i++) {
nl.push(halfl[i]);
nl.push(rest[i]);
}
return nl;
}
function fixContainer(c) {
var children = Array.prototype.filter.call(c.childNodes, a => !!a.id);
children = worst(children.sort(compare));
c.innerHTML = children.map(child => child.outerHTML).join(' ');
}
containers.forEach(c => fixContainer(c));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment