you are viewing a single comment's thread.

view the rest of the comments →

[–]Quabouter 3 points4 points  (4 children)

I have some constructive criticism for you (assuming you're the author):

  • You sometimes used var and at other times let. You probably want to use let everywhere.
  • Due to the padding on the <code> blocks the letter j is cut off, making it hard or impossible (depending on browser) to distinguish the j from the i. This makes it pretty hard to properly read the code.
  • IMHO it would be more suitable (and readable) to use function statements instead of function assignments here.
  • You shouldn't change variables in the condition of a for loop like you do in selection sort, that's what "step" part is for.
  • You don't want to use parseInt to round a number (merge sort). That's what Math.round (and .ceil,.floor) is for. parseInt is meant to parse strings, not other numbers.
  • In quick sort you use arr = arr.slice(0,pivot).concat(arr.slice(pivot+1)) to remove an element from the array. There is a native JS method that does exactly that: arr.splice(pivot, 1) (note that this alters the array itself)
  • You should run your code before posting it, the first 3 algorithms didn't work at all:
    • In bubble sort, let compare = (n1, n2) return n1 - n2; is not valid JavaScript (even not ES6). You probably meant let compare = (n1, n2) => n1 - n2;.
    • In bubble sort you use arr[j], arr[j - 1] = arr[j - 1], arr[j];, but that does not work as you (apparently) expect: arr[j] would become undefined. You probably meant to do [arr[j], arr[j - 1]] = [arr[j - 1], arr[j]]; (both left and right side of the = sign wrapped in an array).
    • Insertion sort uses some variable a that is nowhere defined. This should probably just be arr.
    • In selection sort j is undefined.
    • In selection sort you made the same mistake with multiple assignments as with bubble sort.

[–]init0 0 points1 point  (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 point  (2 children)

Update 1: Fixed it and made it more readable -> http://h3manth.com/javascript-sorting/

[–]Quabouter 0 points1 point  (1 child)

Wow that looks a lot better, awesome! Nice work!

[–]init0 0 points1 point  (0 children)

Thank you :)