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
I just tried to make it more readable for beginners. I can do oneliner in Python and OCaml too.
qs = lambda a: [] if not a else qs([n for n in a if n < a[0]]) + [a[0]] + qs([n for n in a if n > a[0]])
It's still readable, IMO.
So?
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.
I just tried to make it more readable for beginners. I can do oneliner in Python and OCaml too.
It's still readable, IMO.
So?