gpt-3.5-turbo-0301· openai
Suzhen/CodeChat
Fait moi un bout de code typescript pour un algorithmes de tri a bulle
- User
Fait moi un bout de code typescript pour un algorithmes de tri a bulle
- Assistant
Voici un exemple de code TypeScript pour l'algorithme de tri à bulle :
function bubbleSort(array: number[]): number[] { const length = array.length; let swapped: boolean; do { swapped = false; for (let i = 0; i < length - 1; i++) { if (array[i] > array[i + 1]) { const temp = array[i]; array[i] = array[i + 1]; array[i + 1] = temp; swapped = true; } } } while (swapped); return array; } // Exemple d'utilisation de la fonction bubbleSort const unsortedArray = [5, 3, 8, 1, 2, 9, 4, 7, 6]; const sortedArray = bubbleSort(unsortedArray); console.log(sortedArray); // Affiche [1, 2, 3, 4, 5, 6, 7, 8, 9]
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.