Skip to content

Instantly share code, notes, and snippets.

@cernael
Created August 30, 2015 00:31
Show Gist options
  • Save cernael/d2890ad366863f14e6cd to your computer and use it in GitHub Desktop.
Save cernael/d2890ad366863f14e6cd to your computer and use it in GitHub Desktop.
function maximizer(list){
function sortIt(x, y){
x += '';
y += '';
if(x === y){
return 0;
}
if(x.length === y.length){
if(x < y){
return 1;
}
if(x > y){
return -1;
}
}
if(x.length < y.length){
var a = x,
b = y.slice(0, x.length),
c = y.slice(x.length),
test = sortIt(a, b);
if(test !== 0){
return test;
} else {
return sortIt(b+c, c+a);
}
}
if(x.length > y.length){
var a = x.slice(0, y.length),
b = x.slice(y.length),
c = y,
test = sortIt(a, c);
if(test !== 0){
return test;
} else {
return sortIt(b+c, a+b);
}
}
}
return list.sort(sortIt).join('')/1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment