Skip to content
TheChatArchiveThe Chat Archive
gpt-4.1-mini-2025-04-14· OpenAIHugging Face LMArena Human Preference 140K

Write me a quick sort algorithm using javascript

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with o4-mini-2025-04-16’s answer.
  1. User

    Write me a quick sort algorithm using javascript

  2. Assistant

    Sure! Here's a simple implementation of the Quick Sort algorithm in JavaScript:

    function quickSort(arr) {
      if (arr.length <= 1) {
        return arr;
      }
    
      const pivot = arr[arr.length - 1]; // Choose the last element as pivot
      const left = [];
      const right = [];
    
      for (let i = 0; i < arr.length - 1; i++) {
        if (arr[i] < pivot) {
          left.push(arr[i]);
        } else {
          right.push(arr[i]);
        }
      }
    
      return [...quickSort(left), pivot, ...quickSort(right)];
    }
    
    // Example usage:
    const array = [5, 3, 8, 4, 2];
    console.log(quickSort(array)); // Output: [2, 3, 4, 5, 8]
    

    Let me know if you want an in-place version or any explanation!

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.