Skip to content

Instantly share code, notes, and snippets.

@nelsonic
Created April 16, 2013 16:47
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nelsonic/5397503 to your computer and use it in GitHub Desktop.
Save nelsonic/5397503 to your computer and use it in GitHub Desktop.
ASCII Ascending Order Sort Sort in HTML/JavaScript
<html>
<h1>Sort</h1>
<!-- enable the Chrome Developer Console to see Results -->
<script>
str = 'X,a,A,C,D,F,1,c,4,3'
data = str.split(',')
console.dir(data)
counter = 0;
limit = data.length;
end = limit-1;
console.log('Limit:'+limit +' | end: '+end )
for(var i = 0; i < limit-1; i++) {
// console.log(arr[i])
for(var j =0; j < end; j++) {
counter++;
// console.log(data[j] +' ' +data[j+1])
if(data[j] > data[j+1]) {
// console.log(data[j] +' ' +data[j+1])
swap = data[j+1]
data[j+1] = data[j]
data[j] = swap
}
}
end--;
}
console.log('after runnign the loop')
console.dir(data)
console.log(counter)
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment