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

    JavaScript, Algorithm

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

  • K-nearest neighbors

    JavaScript, Algorithm

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

  • Luhn check

    JavaScript, Math

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

  • Heap sort

    JavaScript, Algorithm

    Sorts an array of numbers, using the heapsort algorithm.

  • Index of substrings

    JavaScript, String

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

  • Bucket sort

    JavaScript, Algorithm

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

  • Array permutations

    JavaScript, Array

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

  • Caesar cipher

    JavaScript, Algorithm

    Encrypts or decrypts a given string using the Caesar cipher.

  • Quick sort

    JavaScript, Algorithm

    Sorts an array of numbers, using the quicksort algorithm.

  • Selection sort

    JavaScript, Algorithm

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

  • Count substrings of string

    JavaScript, String

    Counts the occurrences of a substring in a given string.

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

  • Arithmetic progression

    JavaScript, Math

    Creates an array of numbers in the arithmetic progression, starting with the given positive integer and up to the specified limit.

  • Euclidean distance

    JavaScript, Math

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

  • Merge sort

    JavaScript, Algorithm

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