Skip to content

Commit

Permalink
Update Chapter10(Sort).js
Browse files Browse the repository at this point in the history
  • Loading branch information
Sammie Bae authored Jun 11, 2020
1 parent ef9a3aa commit 4c5ba26
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions Chapter10(Sort).js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

function bubbleSort(array) {
for (var i = 0, arrayLength = array.length; i < arrayLength; i++) {
for (var j = 0; j < arrayLength - 1 - i; j++) {
for (var j = 0; j <= i; j++) {
if (array[j] > array[j+1]) {
swap(array, i, j);
}
Expand All @@ -10,14 +9,15 @@ function bubbleSort(array) {
return array;
}

bubbleSort([6, 1, 2, 3, 4, 5]); // [1,2,3,4,5,6]

function swap(array, index1, index2) {
var temp = array[index1];
array[index1] = array[index2];
array[index2] = temp;
}

bubbleSort([6, 1, 2, 3, 4, 5]); // [1,2,3,4,5,6]


function selectionSort(items) {
var len = items.length,
min;
Expand Down

0 comments on commit 4c5ba26

Please sign in to comment.