Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions sorting-algorithms-in-javascript/selection-sort.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
// array to sort
var array = [9, 2, 5, 6, 4, 3, 7, 10, 1, 8];
let array = [9, 2, 5, 6, 4, 3, 7, 10, 1, 8];

// swap function helper
function swap(array, i, j) {
var temp = array[i];
let temp = array[i];
array[i] = array[j];
array[j] = temp;
}

function selectionSort(array) {
for(var i = 0; i < array.length; i++) {
var min = i;
for(var j = i + 1; j < array.length; j++) {
for(let i = 0; i < array.length; i++) {
let min = i;
for(let j = i + 1; j < array.length; j++) {
if(array[j] < array[min]) {
min = j;
}
Expand Down