# 30 seconds of code

## Math

Click on a snippet card to view the snippet.

#### approximatelyEqual

Checks if two numbers are approximately equal to each other.

#### average

Returns the average of two or more numbers.

#### averageBy

Returns the average of an array, after mapping each element to a value using the provided function.

#### binomialCoefficient

Evaluates the binomial coefficient of two integers `n`

and `k`

.

#### clampNumber

Clamps `num`

within the inclusive range specified by the boundary values `a`

and `b`

.

#### degreesToRads

Converts an angle from degrees to radians.

#### digitize

Converts a number to an array of digits.

#### distance

Returns the distance between two points.

#### elo

Computes the new ratings between two or more opponents using the Elo rating system. It takes an array of pre-ratings and returns an array containing post-ratings. The array should be ordered from best performer to worst performer (winner -> loser).

#### factorial

Calculates the factorial of a number.

#### fibonacci

Generates an array, containing the Fibonacci sequence, up until the nth term.

#### gcd

Calculates the greatest common divisor between two or more numbers/arrays.

#### geometricProgression

Initializes an array containing the numbers in the specified range where `start`

and `end`

are inclusive and the ratio between two terms is `step`

.
Returns an error if `step`

equals `1`

.

#### hammingDistance

Calculates the Hamming distance between two values.

#### inRange

Checks if the given number falls within the given range.

#### isDivisible

Checks if the first numeric argument is divisible by the second one.

#### isEven

Returns `true`

if the given number is even, `false`

otherwise.

#### isNegativeZero

Checks if the given value is equal to negative zero (`-0`

).

#### isPrime

Checks if the provided integer is a prime number.

#### lcm

Returns the least common multiple of two or more numbers.

#### luhnCheck

Implementation of the Luhn Algorithm used to validate a variety of identification numbers, such as credit card numbers, IMEI numbers, National Provider Identifier numbers etc.

#### mapNumRange

Maps a number from one range to another range.

#### maxBy

Returns the maximum value of an array, after mapping each element to a value using the provided function.

#### median

Returns the median of an array of numbers.

#### midpoint

Calculates the midpoint between two pairs of (x,y) points.

#### minBy

Returns the minimum value of an array, after mapping each element to a value using the provided function.

#### percentile

Uses the percentile formula to calculate how many numbers in the given array are less or equal to the given value.

#### powerset

Returns the powerset of a given array of numbers.

#### primes

Generates primes up to a given number, using the Sieve of Eratosthenes.

#### radsToDegrees

Converts an angle from radians to degrees.

#### randomIntArrayInRange

Returns an array of n random integers in the specified range.

#### randomIntegerInRange

Returns a random integer in the specified range.

#### randomNumberInRange

Returns a random number in the specified range.

#### round

Rounds a number to a specified amount of digits.

#### sdbm

Hashes the input string into a whole number.

#### standardDeviation

Returns the standard deviation of an array of numbers.

#### sum

Returns the sum of two or more numbers/arrays.

#### sumBy

Returns the sum of an array, after mapping each element to a value using the provided function.

#### sumPower

Returns the sum of the powers of all the numbers from `start`

to `end`

(both inclusive).

#### toSafeInteger

Converts a value to a safe integer.

#### vectorDistance

Returns the distance between two vectors.