gpt-4.1-mini-2025-04-14· OpenAI
LMArena Human Preference 140K
Write me a quick sort algorithm using javascript
- User
Write me a quick sort algorithm using javascript
- 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!
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.