Formatting numeric values in JavaScript
Learn common number formatting operations, such as rounding, padding, optional decimal marks, currency, seconds, bytes, and more.
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.
Learn common number formatting operations, such as rounding, padding, optional decimal marks, currency, seconds, bytes, and more.
Learn how to easily convert between the various color formats, using JavaScript and a few simple formulas.
Calculate the ranking of an array based on a comparator function in JavaScript.
Implement the Luhn Algorithm, used to validate a variety of identification numbers.
When working with JavaScript arrays, you might need the minimum or maximum value. Here are a few quick and easy ways to do it.
SDBM is a simple, non-cryptographic hash function that can hash strings into whole numbers. Here's a JavaScript implementation.
Roman numerals are often used for stylistic reasons, but converting an integer to a roman numeral can be a bit tricky.
Learn how to check if a number is prime and how to generate prime numbers up to a given number in JavaScript.
Use JavaScript's Math.hypot()
to calculate the Euclidean distance between two points.
Create an array of partial sums, using Array.prototype.reduce()
and Array.prototype.slice()
.
Given a sorted array, find the correct index to insert a given value.
Learn how to work with arrays of numbers in JavaScript, performing common math operations such as sum, average, product and more.
Create arrays of numbers in arithmetic and geometric progression.
Converts a number to an array of digits, removing its sign if necessary.
Learn how to create a unit converter data structure in JavaScript that can convert between any compatible units.
Use JavaScript to calculate the greatest common divisor and least common multiple of two or more numbers.
Finds a contiguous subarray with the largest sum within an array of numbers.
Generate the powerset of a given array of numbers or other primitive values.
Calculates the sum of the powers of all the numbers from start
to end
(both inclusive).
Create a new array out of the two supplied by creating each possible pair from the arrays.
Converts a number in bytes to a human-readable string.
When formatting decimal values in JavaScript, trailing zeros can be undesired. Here's how to deal with them.
Generates an array, containing the Fibonacci sequence, up until the nth term.
Find the prime factors of a number using trial division in JavaScript.