re: Sorting Algorithms with Javascript (Part 2) VIEW POST

VIEW FULL DISCUSSION

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 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))] : [];
}

Wow! I've never written a line of ruby in my life πŸ˜… This is really clean.

code of conduct - report abuse