Created
July 18, 2015 17:16
-
-
Save genert/b7cae9df779f31570965 to your computer and use it in GitHub Desktop.
bubbleSort.es6.js
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
class BubbleSort { | |
private Sorter (arrayList, order) { | |
var temp; | |
for (var i = 0; i < arrayList.length - 1; i++) { | |
for (var j = i; j < arrayList.length - i; j++) { | |
if ((order == 'asc' ? (arrayList[j-1] > arrayList[j]) : (arrayList[j-1] < arrayList[j]))) { | |
temp = arrayList[j-1]; | |
arrayList[j-1] = arrayList[j]; | |
arrayList[j] = temp; | |
} | |
} | |
} | |
} | |
Ascending (arrayList) { | |
if (!arrayList.length) { | |
return; | |
} | |
Sorter(arraylist, 'asc'); | |
} | |
Descending (arrayList) { | |
if (!arrayList.length) { | |
return; | |
} | |
Sorter(arraylist, 'desc'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
short and sweet in es6