Last active
March 29, 2016 11:02
-
-
Save alajmo/dfa6765e345c08b850cc to your computer and use it in GitHub Desktop.
Sorting algorithms written in javascript.
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
| // Insertion sort. | |
| var i = a.length; | |
| var j; | |
| while (i--) { | |
| j = i; | |
| while (j > 0 && a[j - 1] > a[j]) { | |
| a[j] = a[j - 1] + (a[j - 1] = a[j]) - a[j]; | |
| j += 1; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://jsperf.com/native-sort-vs-insertion-sort-for-small-arrays