Start of main content
## JavaScript Math 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.

### Product of numeric values

Calculates the product of two or more numbers/arrays.

JavaScript, Math · Oct 22, 2020

### Insertion index in sorted array

Finds the lowest index at which a value should be inserted into an array in order to maintain its sorting order.

JavaScript, Array · Oct 22, 2020

### Number to fixed-point notation without trailing zeros

Formats a number using fixed-point notation, if it has decimals.

JavaScript, Math · May 10, 2022

### Random integer in range

Generates a random integer in the specified range.

JavaScript, Math · Oct 22, 2020

### Random number in range

Generates a random number in the specified range.

JavaScript, Math · Oct 22, 2020

### Number to currency string

Takes a number and returns it in the specified currency formatting.

JavaScript, Math · Oct 22, 2020

### Number to ordinal suffix

Takes a number and returns it as a string with the correct ordinal indicator suffix.

JavaScript, Math · Nov 13, 2020

### JavaScript's numeric separators explained

Numeric separators are a somewhat lesser-known JavaScript syntactic sugar that can make working with large constants a lot easier.

JavaScript, Math · Jun 27, 2021

### Binomial coefficient

Calculates the number of ways to choose

`k`

items from`n`

items without repetition and without order.JavaScript, Math · Dec 28, 2020

### Tip: Convert decimal number to hexadecimal

Ever needed to convert a decimal number to hexadecimal? Here's a quick and easy way to do it.

JavaScript, Math · Sep 21, 2022