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.

  • K-means clustering

    Groups the given data into k clusters, using the k-means clustering algorithm.

    JavaScript, Algorithm · Dec 29, 2020

  • K-nearest neighbors

    Classifies a data point relative to a labelled data set, using the k-nearest neighbors algorithm.

    JavaScript, Algorithm · Oct 13, 2021

  • Luhn check

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

    JavaScript, Math · Jan 30, 2022

  • Array permutations

    Generates all permutations of an array's elements (contains duplicates).

    JavaScript, Array · Dec 28, 2020

  • Heap sort

    Sorts an array of numbers, using the heapsort algorithm.

    JavaScript, Algorithm · Dec 28, 2020

  • Bucket sort

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

    JavaScript, Algorithm · Dec 29, 2020

  • Index of substrings

    Finds all the indexes of a substring in a given string.

    JavaScript, String · Dec 31, 2020

  • Quick sort

    Sorts an array of numbers, using the quicksort algorithm.

    JavaScript, Algorithm · Oct 13, 2021

  • Big-O Cheat Sheet

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

    JavaScript, Algorithm · Jan 8, 2023

  • Caesar cipher

    Encrypts or decrypts a given string using the Caesar cipher.

    JavaScript, Algorithm · Dec 29, 2020

  • Selection sort

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

    JavaScript, Algorithm · Oct 13, 2021

  • Count substrings of string

    Counts the occurrences of a substring in a given string.

    JavaScript, String · Jan 7, 2021

  • Primes up to given number

    Generates primes up to a given number, using the Sieve of Eratosthenes.

    JavaScript, Math · Dec 28, 2020

  • Euclidean distance

    Calculates the distance between two points in any number of dimensions.

    JavaScript, Math · Dec 28, 2020

  • Maximum subarray

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

    JavaScript, Algorithm · Sep 7, 2022