Skip to content

Instantly share code, notes, and snippets.

@George-Hudson
Forked from stevekinney/gist:9e9cfeb225c8133fda73
Last active December 7, 2015 14:03
Show Gist options
  • Save George-Hudson/5f4e90b408b53cd253b4 to your computer and use it in GitHub Desktop.
Save George-Hudson/5f4e90b408b53cd253b4 to your computer and use it in GitHub Desktop.
**Step One**: Watch [Sorting Algorithms in JavaScript](https://www.youtube.com/watch?v=uRyqlhjXYQI)
**Step Two**: Fork this gist.
**Step Three**: Respond to this question in your fork: "What are some of the balances and trade offs between different sorting algoritms?"
* ECMA doesn't have a standart for what sorting alogorithm a browser uses
* .sort() -- 10 < 7
* .sort( function (a,b) { return a-b }); -- decending
* .sort( function (a,b) { return b-a }); -- ascending
* O(x) -- worst case scenario
* merge sort -- fast but takes up lots of memory, divides the responsibility for sorting (makes it logn!), O(n log n)
* insert sort -- slow but doesn't take as much memory, good for arrays that are mostly sorted already and small arrays. O(n^2)
* bubble sort -- even if the array is sorted, it still checks everything and O(n^2), also not stable, **DO NOT USE**
**Step Four**: _Totally Optional_: take a look at some of the other forks and comment if the spirit moves you.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment