Sorting a list of items into ascending or descending order can help either a human or a computer find items on that list quickly, perhaps using an algorithm like binary search. JavaScript has a built-in sorting method. It works on arrays of numbers, or even on arrays of strings:
var animals = ["gnu", "zebra", "antelope", "aardvark", "yak", "iguana"];
Even though JavaScript has a built-in sorting method, sorting is a great example of how there may be many ways to think about the same problem, some perhaps better than others. Understanding sorting is a traditional first step towards mastery of algorithms and computer science.
You'll implement a particular sorting algorithm in a moment. But as a warmup, here is a sorting problem to play with. You can swap any pair of cards by clicking on one card, and then the other. Swap cards until the cards are sorted with smallest card on the left.
Quelle stratégie as-tu utilisé pour trier les cartes? Ta stratégie a-t-elle changé au cours du tri?

Ce contenu a été réalisé par Thomas Cormen et Devin Balkcom, professeurs à l'Université de Dartmouth, en association avec l'équipe de Khan Academy consacrée à la branche informatique. Ce contenu est sous licence CC-BY-NC-SA.