Created
August 21, 2014 23:51
-
-
Save tmaeda1981jp/9c643e2332af9439843c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*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