We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 8fed565 commit d1caf49Copy full SHA for d1caf49
solutions/javascript/quick-sort.js
@@ -1,11 +1,13 @@
1
-module.exports = function quickSort (array, compare) {
+'use strict';
2
+
3
+module.exports = function quickSort(input, compare) {
4
var lesser = [],
5
greater = [],
6
pivot;
7
8
// Not an array, empty or array of 1 is already sorted
- if (!Array.isArray(array) || array.length < 2) {
- return array;
9
+ if (!Array.isArray(input) || input.length < 2) {
10
+ return input;
11
}
12
13
// Create a compare func if not passed in
@@ -15,6 +17,8 @@ module.exports = function quickSort (array, compare) {
15
17
};
16
18
19
20
+ var array = input.slice(0); // make a copy of the array
21
22
// Get our pivot, this can be random
23
pivot = array.splice(~~(Math.random() * array.length), 1);
24
0 commit comments