-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: resolve lint issues so the project is clean (#98)
- Loading branch information
Showing
6 changed files
with
58 additions
and
50 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,40 @@ | ||
function swap(items, leftIndex, rightIndex){ | ||
var temp = items[leftIndex]; | ||
items[leftIndex] = items[rightIndex]; | ||
items[rightIndex] = temp; | ||
var temp = items[leftIndex]; | ||
items[leftIndex] = items[rightIndex]; | ||
items[rightIndex] = temp; | ||
} | ||
function partition(items, left, right) { | ||
var pivot = items[Math.floor((right + left) / 2)], //middle element | ||
i = left, //left pointer | ||
j = right; //right pointer | ||
while (i <= j) { | ||
while (items[i] < pivot) { | ||
i++; | ||
} | ||
while (items[j] > pivot) { | ||
j--; | ||
} | ||
if (i <= j) { | ||
swap(items, i, j); //sawpping two elements | ||
i++; | ||
j--; | ||
} | ||
var pivot = items[Math.floor((right + left) / 2)], //middle element | ||
i = left, //left pointer | ||
j = right; //right pointer | ||
while (i <= j) { | ||
while (items[i] < pivot) { | ||
i++; | ||
} | ||
return i; | ||
while (items[j] > pivot) { | ||
j--; | ||
} | ||
if (i <= j) { | ||
swap(items, i, j); //sawpping two elements | ||
i++; | ||
j--; | ||
} | ||
} | ||
return i; | ||
} | ||
|
||
function quickSort(items, left, right) { | ||
var index; | ||
if (items.length > 1) { | ||
index = partition(items, left, right); //index returned from partition | ||
if (left < index - 1) { //more elements on the left side of the pivot | ||
quickSort(items, left, index - 1); | ||
} | ||
if (index < right) { //more elements on the right side of the pivot | ||
quickSort(items, index, right); | ||
} | ||
var index; | ||
if (items.length > 1) { | ||
index = partition(items, left, right); //index returned from partition | ||
if (left < index - 1) { //more elements on the left side of the pivot | ||
quickSort(items, left, index - 1); | ||
} | ||
if (index < right) { //more elements on the right side of the pivot | ||
quickSort(items, index, right); | ||
} | ||
return items; | ||
} | ||
return items; | ||
} | ||
|
||
module.exports.quickSort = quickSort; |
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
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