0% found this document useful (0 votes)
5 views1 page

Ss 1

The article discusses common sorting algorithms in computer science, emphasizing their importance in reducing problem complexity and their applications in various algorithms. It covers Bubble Sort, Selection Sort, Insertion Sort, Merge Sort, Quick Sort, and Bucket Sort. Additionally, it introduces helper methods for swapping elements and comparing values in arrays.

Uploaded by

sivangsantonino
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views1 page

Ss 1

The article discusses common sorting algorithms in computer science, emphasizing their importance in reducing problem complexity and their applications in various algorithms. It covers Bubble Sort, Selection Sort, Insertion Sort, Merge Sort, Quick Sort, and Bucket Sort. Additionally, it introduces helper methods for swapping elements and comparing values in arrays.

Uploaded by

sivangsantonino
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Common Sorting Algorithms in JavaScript

#javascript #beginners #webdev #algorithms

In this article, I will cover some common sorting algorithms in computer science. Sorting
algorithms are important to study because they can often reduce the complexity of a problem.
They also have direct applications in searching algorithms, database algorithms, and much
more.

Sorting algorithms we will learn about:

 Bubble Sort
 Selection Sort
 Insertion Sort
 Merge Sort
 Quick Sort
 Bucket Sort

Helper Methods for Swapping and Comparing


We will be swapping elements in arrays a lot so let's start by writing a helper method called
swap:

function swap(arr, a, b) {
let temp = arr[a];
arr[a] = arr[b];
arr[b] = temp;
}

We will be comparing elements a lot so I think it's a good idea to write a function for just
that:

const Compare = {
LESS_THAN: -1,
BIGGER_THAN: 1
};

function defaultCompare(a, b) {
if (a === b) {
return 0;
}
return a < b ? Compare.LESS_THAN : Compare.BIGGER_THAN;
}

Okay, now that that's settled, let's move onto sorting!

You might also like