Skip to content

Instantly share code, notes, and snippets.

@tmaeda1981jp
Created August 21, 2014 23:51
Show Gist options
  • Save tmaeda1981jp/9c643e2332af9439843c to your computer and use it in GitHub Desktop.
Save tmaeda1981jp/9c643e2332af9439843c to your computer and use it in GitHub Desktop.
/*jslint white: true, nomen: true, maxlen: 120, plusplus: true, */
/*global _:false, $:false, define:false, require:false, */
var result = (function(array) {
if (array.length < 2) { return array; }
var base = array[Math.ceil(array.length / 2)],
central = [],
lower = [],
upper = [];
array.forEach(function(c) {
if (c < base) {
lower.push(c);
}
else if (c > base) {
upper.push(c);
}
else {
central.push(c);
}
});
return arguments.callee(lower)
.concat(central)
.concat(arguments.callee(upper));
}([
'u', 'y', 'd', 'n', 'j', 'a', 'm', 'r', 'l', 'k', 't', 'b', 'f',
'o', 'p', 'c', 'h', 'e', 'v', 'w', 's', 'z', 'g', 'i', 'q', 'x',
]));
console.log(result);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment