quicksort in Ruby. Short and clear.
def qs a (pivot = a.pop) ? qs(a.select{|i| i <= pivot}) + [pivot] + qs(a.select{|i| i > pivot}) : [] end
Wow! I've never written a line of ruby in my life 😅 This is really clean.
I can do pretty much the same in javascript. :)
const qs = (a) => { const pivot = a.pop(); return pivot != null ? [...qs(a.filter(i => i < pivot)), pivot, ...qs(a.filter(i => i >= pivot))] : []; }
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
quicksort in Ruby. Short and clear.
Wow! I've never written a line of ruby in my life 😅 This is really clean.
I can do pretty much the same in javascript. :)