Created
April 25, 2017 10:46
-
-
Save pawarvijay/f0dea040be9db4c92182c327390b0bfa to your computer and use it in GitHub Desktop.
Sort numbers without effecting alphabets - sort by selection sort
This file contains hidden or 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
function selectionSort(items) | |
{ | |
console.log(items) | |
var length = items.length; | |
for (var i = 0; i < length - 1; i++) | |
{ | |
var min = i; | |
for (var j = i + 1; j < length; j++) | |
{ | |
if (typeof items[j] === 'string') { | |
} else { | |
console.log('items[j] ' + items[j] + ' items[min] ' + items[min]) | |
if (items[j] < items[min]) | |
{ | |
min = j; | |
} | |
} | |
} | |
if (min != i) | |
{ | |
var tmp = items[i]; | |
items[i] = items[min]; | |
items[min] = tmp; | |
console.log(items); | |
} | |
} | |
} | |
selectionSort([9, 'p', 'a', 5, 3, 'i', 7, 1, 'b', 4, 8]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment