Skip to content

Instantly share code, notes, and snippets.

@PulkitAgg
Created December 17, 2018 07:15
Show Gist options
  • Save PulkitAgg/5ab12486dcb84c221e97e3bf118a75e1 to your computer and use it in GitHub Desktop.
Save PulkitAgg/5ab12486dcb84c221e97e3bf118a75e1 to your computer and use it in GitHub Desktop.
Chronological Order Sorting Using Bubble Sort.
//Problem: You have to sort the string array in chronological order without using any external sorting method.
//Solution:
A = ["ab","aa","ca",'ab']; // user input
for(let count=0; count< A.length; count++) {
for(let innerCount=0; innerCount<A.length - count -1; innerCount++) {
if(A[innerCount] > A[innerCount+1]) {
// swap the elements.
let temp = A[innerCount+1];
A[innerCount+1] = A[innerCount];
A[innerCount] = temp;
}
}
}
console.log(A); // print the sorted array.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment