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.

  • arithmeticProgression

    JavaScript, Math

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

  • binarySearch

    JavaScript, Algorithm

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

  • binomialCoefficient

    JavaScript, Math

    Calculates the number of ways to choose k items from n items without repetition and without order.

  • bubbleSort

    JavaScript, Algorithm

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

  • bucketSort

    JavaScript, Algorithm

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

  • caesarCipher

    JavaScript, Algorithm

    Encrypts or decrypts a given string using the Caesar cipher.

  • countSubstrings

    JavaScript, String

    Counts the occurrences of a substring in a given string.

  • distance

    JavaScript, Math

    Calculates the distance between two points.

  • euclideanDistance

    JavaScript, Math

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

  • factorial

    JavaScript, Math

    Calculates the factorial of a number.

  • fibonacci

    JavaScript, Math

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

  • gcd

    JavaScript, Math

    Calculates the greatest common divisor between two or more numbers/arrays.

  • geometricProgression

    JavaScript, Math

    Initializes an array containing the numbers in the specified range where start and end are inclusive and the ratio between two terms is step. Returns an error if step equals 1.

  • hammingDistance

    JavaScript, Math

    Calculates the Hamming distance between two values.

  • heapsort

    JavaScript, Algorithm

    Sorts an array of numbers, using the heapsort algorithm.