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

Show parent comments

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.