JavaScript Snippets

The JavaScript snippet collection contains a wide variety of ES6 helper functions. It includes helpers for dealing with primitives, arrays and objects, as well as algorithms, DOM manipulation functions and Node.js utilities.

  • addClass

    JavaScript, Browser

    Adds a class to an HTML element.

  • addStyles

    JavaScript, Browser

    Adds the provided styles to the given element.

  • all

    JavaScript, Array

    Checks if the provided predicate function returns true for all elements in a collection.

  • allEqual

    JavaScript, Array

    Checks if all elements in an array are equal.

  • allUnique

    JavaScript, Array

    Checks if all elements in an array are unique.

  • any

    JavaScript, Array

    Checks if the provided predicate function returns true for at least one element in a collection.

  • approximatelyEqual

    JavaScript, Math

    Checks if two numbers are approximately equal to each other.

  • arithmeticProgression

    JavaScript, Math

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

  • atob

    JavaScript, Node

    Decodes a string of data which has been encoded using base-64 encoding.

  • average

    JavaScript, Math

    Calculates the average of two or more numbers.

  • 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.

  • bottomVisible

    JavaScript, Browser

    Checks if the bottom of the page is visible.

  • btoa

    JavaScript, Node

    Creates a base-64 encoded ASCII string from a String object in which each character in the string is treated as a byte of binary data.

  • bubbleSort

    JavaScript, Algorithm

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