Created
August 23, 2016 02:30
-
-
Save dengjonathan/32857c21253fd3013fee9e221f4fc1c3 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
// implementation of quicksort | |
var quickSort = function (arr) { | |
if (arr.length === 0) { | |
return []; | |
} | |
var left = []; | |
var right = []; | |
var pivot = arr[arr.length - 1]; // use right most value as pivot | |
_.each(arr.slice(0, arr.length - 1), function (each) { | |
if (each <= pivot) { | |
left.push(each); | |
} else { | |
right.push(pivot); | |
} | |
}); | |
return quickSort(left).concat(pivot, quickSort(right)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment