r/webdev • • Mar 01 '17

Programmers are confessing their coding sins to protest a broken job interview process

https://theoutline.com/post/1166/programmers-are-confessing-their-coding-sins-to-protest-a-broken-job-interview-process
1.4k Upvotes

341 comments sorted by

View all comments

2

u/Axumata Mar 02 '17 edited Mar 02 '17

Hi, I'm Axumata, and I implemented that Array.prototype.bubbleSort() in 10 minutes, but JS already has Array.prototype.sort(), which supports custom compare functions, so what's the point? I don't have a real webdev job anyway (that requires whiteboard interviews), just sperging about JS.

Update: bubble sort is way faster.

1

u/smartello Mar 02 '17

Way faster with an average complexity of sqare n?

2

u/Axumata Mar 02 '17

way faster until it hits recursion limit

1

u/smartello Mar 02 '17

Recursion in bubbleSort? Now I confused even more and not sure that we speak about the same thing. Bubble Sort is based on two cycles nested to each other, isn't it?

2

u/Axumata Mar 02 '17

Yep, but if we replace outer loop with recursively calling the inner loop, it won't change much, except when handling really big arrays:

https://jsperf.com/bubble-sort-recursive-and-iterative-vs-native-sort-1/1

1

u/smartello Mar 02 '17

Ok, now I got it. Still have no idea how comparison function is converted into sorting in js internally, but I'm really surprised how bad it is out of the box. Surprised by recursion that is more efficient as well but it's logical when you think about it. Thank you for this example, appreciate it.