Home
← All questions

Custom Array.sort using QuickSort in JavaScript

MediumPremiumJavaScript

Asked at Freshworks

JavaScript interview practice: Write a custom polyfill for Array.sort using the QuickSort algorithm with partitioning and recursion.

Problem

Implement mySort(arr, comparator) using QuickSort. The comparator follows the native convention: negative if a before b, positive if a after b. Default to ascending numeric/lexicographic order.

function mySort(arr, comparator) {
  // QuickSort here
}
Premium question

Unlock the in-browser editor, test cases, and model solution with Mentoxis Premium.

Unlock with Premium