Fibonacci
Generates an array, containing the Fibonacci sequence, up until the nth term.
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.
Generates an array, containing the Fibonacci sequence, up until the nth term.
Combining Math.random()
and a few simple math operations, you can generate an array of random integers in a specified range.
Calculates the distance between two vectors.
Calculates the angle (theta) between two vectors.
Find the prime factors of a number using trial division in JavaScript.
Calculates the percentage of numbers in the given array that are less or equal to the given value.
Clamping and mapping a number to a range are two common and easily confused operations. Learn how to perform each in JavaScript.
Ever needed to convert a decimal number to hexadecimal? Here's a quick and easy way to do it.
Enhance JavaScript's Math.random()
to generate a random number or integer in a specified range.
Calculates the Hamming distance between two values.
Implement Python's divmod()
built-in function in one line of JavaScript.
Get started with logical operations in JavaScript with this collection of helper functions.
Numeric separators are a somewhat lesser-known JavaScript syntactic sugar that can make working with large constants a lot easier.
A quick, one-liner to generate a random boolean value in JavaScript.
Calculates the number of ways to choose k
items from n
items without repetition and without order.
Calculates the factorial of a number.
Calculates the midpoint between two pairs of (x,y) points.
Check if a number is even or odd using JavaScript using the modulo operator or bitwise AND operator.
While both the prefix and postfix operators increment a value, the resulting value of the expression is very different.
Checks if the given number falls within the given range.
Calculate the logarithm of a number or check if a number is a power of a specific base.
Checks if the given value is a number.
Returns the absolute value of the first number, but the sign of the second.
Learn how to check if two numbers are approximately equal to each other in JavaScript.