Created
June 23, 2015 14:16
-
-
Save goesang/0fe543a5c9d4015b84f8 to your computer and use it in GitHub Desktop.
퀵 정렬 자바스크립트 간단 버젼
This file contains hidden or 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
function quickSort(arr){ | |
if(arr.length < 2) | |
return arr; | |
var pivot = arr[Math.floor(arr.length/2)]; | |
var middle = arr.filter(function (data) {return data == pivot;}); | |
var lows = quickSort(arr.filter(function (data) {return data < pivot;})); | |
var highs = quickSort(arr.filter(function (data) {return data > pivot;})); | |
return lows.concat(middle).concat(highs); | |
} | |
alert(quickSort([0,50,6,3,5,2,1,2])); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment