function selectionSort(items) {

	// For each item in the array
	for (var i = 1; i < items.length; i++) {

		var j = i;

		// Compare the item to every item before it
		// If the value of that item is less than the value of that item before it, swap the two
		while (j > 0 && items[j-1] > items[j]) {
			swap(items, j-1, j);
			j--;
		}
	}

	return items;
}
// Keep comparing until that position 1) does not get swapped or 2) reaches the beginning of the array
Keep comparing until that position 1) does not get swapped or 2) reaches the beginning of the array
Keep comparing until that position 1 ) does not get swapped or 2 ) reaches the beginning of the array
function selectionSort(items) {
	for (var i = 1; i < items.length; i++) {
		var j = i;
		while (j > 0 && items[j-1] > items[j]) {
			swap(items, j-1, j);
			j--;
		}
	}
	return items;
}
function selectionSort ( items ) { for ( var i = 1 ; i < items . length ; i ++ ) { var j = i ; while ( j > 0 && items [ j - 1 ] > items [ j ] ) { swap ( items , j - 1 , j ) ; j -- ; } } return items ; }
Keep comparing until that position 1) does not get swapped or 2) reaches the beginning of the array
Keep comparing until that position 1 ) does not get swapped or 2 ) reaches the beginning of the array
// For each item in the array // Compare the item to every item before it // If the value of that item is less than the value of that item before it, swap the two