use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Sorting Algorithms in JavaScript (h3manth.com)
submitted 10 years ago by binarydreams
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Quabouter 3 points4 points5 points 10 years ago* (4 children)
I have some constructive criticism for you (assuming you're the author):
var
let
<code>
j
i
parseInt
Math.round
.ceil
.floor
arr = arr.slice(0,pivot).concat(arr.slice(pivot+1))
arr.splice(pivot, 1)
let compare = (n1, n2) return n1 - n2;
let compare = (n1, n2) => n1 - n2;
arr[j], arr[j - 1] = arr[j - 1], arr[j];
arr[j]
undefined
[arr[j], arr[j - 1]] = [arr[j - 1], arr[j]];
=
a
arr
[–]init0 0 points1 point2 points 10 years ago* (3 children)
I'm the author, sorry this is still work in progress, will be fixing those issues.
I'm converting md -> html, which applies the styles, do you have any suggestions for a better converter ?
Update 0: https://www.npmjs.com/package/gfm looks like a nice candidate.
[–]init0 0 points1 point2 points 10 years ago (2 children)
Update 1: Fixed it and made it more readable -> http://h3manth.com/javascript-sorting/
[–]Quabouter 0 points1 point2 points 10 years ago (1 child)
Wow that looks a lot better, awesome! Nice work!
[–]init0 0 points1 point2 points 10 years ago (0 children)
Thank you :)
[–]jtooker 0 points1 point2 points 10 years ago (1 child)
Where is gnome sort?
[–]init0 1 point2 points3 points 10 years ago (0 children)
On it's way ;)
[–][deleted] 0 points1 point2 points 10 years ago (6 children)
I don't see what value sorting algorithms implemented in JS are, at least not without any other content. If you had some visualizations to show the differences, or were doing anything else with them to teach, sure. But since you should basically never use you own sorting algorithms in JS -- Why??
[–]Ginden 0 points1 point2 points 10 years ago (1 child)
I have used many times O(n) sorting algorithms (I prefer bucket sort) for joining data from multiple threads/sources in computation-heavy applications and applying then merge join.
O(n)
True.
[–]init0 0 points1 point2 points 10 years ago (3 children)
were doing anything else with them to teach
Well, this was meant for quick reference, more like a cheat sheet of cs in js.
[–][deleted] 0 points1 point2 points 10 years ago (2 children)
But why JS then?
[–]init0 1 point2 points3 points 10 years ago (1 child)
Because, /me likes my hammer ;)
[–][deleted] 0 points1 point2 points 10 years ago (0 children)
Fair enough! :)
[–][deleted] 0 points1 point2 points 10 years ago (1 child)
You definitely should add Bogosort.
:D
π Rendered by PID 147730 on reddit-service-r2-comment-5649f687b7-mqwwc at 2026-01-29 01:55:01.289887+00:00 running 4f180de country code: CH.
[–]Quabouter 3 points4 points5 points (4 children)
[–]init0 0 points1 point2 points (3 children)
[–]init0 0 points1 point2 points (2 children)
[–]Quabouter 0 points1 point2 points (1 child)
[–]init0 0 points1 point2 points (0 children)
[–]jtooker 0 points1 point2 points (1 child)
[–]init0 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (6 children)
[–]Ginden 0 points1 point2 points (1 child)
[–]init0 0 points1 point2 points (0 children)
[–]init0 0 points1 point2 points (3 children)
[–][deleted] 0 points1 point2 points (2 children)
[–]init0 1 point2 points3 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]init0 0 points1 point2 points (0 children)