Skip to content

Sorting Algorithms

Arghun-dev edited this page Jul 31, 2021 · 16 revisions

Examples

  1. Sorting numbers from smallest to largest
  2. Sorting names alphabetically
  3. Sorting movies based on release year

Why do we need to learn this?

. Sorting is an incredibly common taks, so it's good to know how it works . there are many different ways to sort things, and different techniques have their own advantages and disadvantages

JavaScript Built in sort method

...but it doesn't always work the way you expect

example:

["Steele", "Colt", "Data Structure", "Algorithms"].sort() =>

["Algorithms", "Colt", "Data Structures", "Steele"]

that make sense, that sorted alphabetically.

another example:

[6, 4, 15, 10].sort() => [10, 15, 4, 6] => that does not make sense.

Clone this wiki locally