Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Hey, love it! I know that you know it can handle duplicates, but a simple fix can work here.

Make an array called `equal` before making the `less` and `greater` arrays.

  const equal = arr.filter(i => i === pivot);
Then, instead of adding the pivot, add the equal array.

  return [
    ...quicksort(less),
    ...equal,
    ...quicksort(greater)
  ]


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: