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.

### Prime factors of number

Finds the prime factors of a given number using the trial division algorithm.

JavaScript, Math · Dec 28, 2020

### Random integer array in range

Generates an array of

`n`

random integers in the specified range.JavaScript, Math · Oct 22, 2020

### Array symmetric difference

Returns the symmetric difference between two arrays, without filtering out duplicate values.

JavaScript, Array · Oct 22, 2020

### RGB to hex

Converts the values of RGB components to a hexadecimal color code.

JavaScript, String · Nov 3, 2020

### Standard deviation

Calculates the standard deviation of an array of numbers.

JavaScript, Math · Oct 22, 2020

### Weighted average

Calculates the weighted average of two or more numbers.

JavaScript, Math · Nov 3, 2020

### Array unique symmetric difference

Returns the unique symmetric difference between two arrays, not containing duplicate values from either array.

JavaScript, Array · Oct 22, 2020

### Array similarity

Returns an array of elements that appear in both arrays.

JavaScript, Array · Oct 22, 2020

### Least common multiple

Calculates the least common multiple of two or more numbers.

JavaScript, Math · Dec 28, 2020

### Percentile of matches

Calculates the percentage of numbers in the given array that are less or equal to the given value.

JavaScript, Math · Oct 22, 2020