# JavaScript Algorithms

The JavaScript algorithms collection includes implementations and examples of popular algorithms in ES6. Algorithmic snippets are primarily a learning resource, as they might already be implemented natively or require optimizations to run in production.

• JavaScript ·

### Group data using the K-means clustering algorithm in JavaScript

Implement the K-means clustering algorithm in JavaScript to group data into clusters.

• JavaScript ·

### Classify data using the K-nearest neighbors algorithm in JavaScript

Implement the K-nearest neighbors algorithm in JavaScript to classify a data point relative to a labelled data set.

• JavaScript ·

### Heap sort

Sort an array of numbers, using the heapsort algorithm.

• JavaScript ·

### Selection sort

Sort an array of numbers, using the selection sort algorithm.

• JavaScript ·

### Quick sort

Sort an array of numbers, using the quicksort algorithm.

• JavaScript ·

### Implementing the Luhn Algorithm in JavaScript

Implement the Luhn Algorithm, used to validate a variety of identification numbers.

• JavaScript ·

### Implement the Caesar cipher in JavaScript

The Caesar cipher is a simple substitution cipher, which can be easily implemented with a few lines of JavaScript code.

• JavaScript ·

### Bucket sort

Sort an array of numbers, using the bucket sort algorithm.

• JavaScript ·

### Big-O Cheat Sheet

Learn everything you need to know about Big-O notation with this handy cheatsheet.

• JavaScript ·

### Merge sort

Sort an array of numbers, using the merge sort algorithm.

• JavaScript ·

### Check if a number is prime in JavaScript

Learn how to check if a number is prime and how to generate prime numbers up to a given number in JavaScript.

• JavaScript ·

### Calculate the Euclidean distance in JavaScript

Use JavaScript's `Math.hypot()` to calculate the Euclidean distance between two points.

• JavaScript ·

### Insertion sort

Sort an array of numbers, using the insertion sort algorithm.

• JavaScript ·

### Arithmetic and geometric progression in JavaScript

Create arrays of numbers in arithmetic and geometric progression.

• JavaScript ·

### Calculate the Levenshtein distance between two strings in JavaScript

Implement the Levenshtein distance algorithm in JavaScript to calculate the difference between two strings.

• JavaScript ·

### Maximum subarray

Finds a contiguous subarray with the largest sum within an array of numbers.

• JavaScript ·

### How can I calculate the greatest common divisor & least common multiple in JavaScript?

Use JavaScript to calculate the greatest common divisor and least common multiple of two or more numbers.

• JavaScript ·

### Bubble sort

Sort an array of numbers, using the bubble sort algorithm.

• JavaScript ·

### Fibonacci

Generates an array, containing the Fibonacci sequence, up until the nth term.

• JavaScript ·

### Binary search

Finds the index of a given element in a sorted array using the binary search algorithm.

• JavaScript ·

### Linear search

Finds the first index of a given element in an array using the linear search algorithm.

• JavaScript ·

### Find the prime factors of a number in JavaScript

Find the prime factors of a number using trial division in JavaScript.

• JavaScript ·

### Hamming distance

Calculates the Hamming distance between two values.

• JavaScript ·

### Factorial of number

Calculates the factorial of a number.

Start typing a keyphrase to see matching snippets.