Nexium

Numbers

Unlock the Power of Numbers with Nexium's Essential Methods

Import the NNumber

const { NNumber } = require('nexium')

clamp

Restricts a number to be within a specified range

const result = NNumber.clamp(15, 0, 10) // 10

inRange

Check if a number falls within a specified range

const result = NNumber.inRange(5, 1, 10) // true

roundTo

Round a number to a specific number of decimal places

const result = NNumber.roundTo(3.14159, 2) // 3.14

generateRandom

Generate random number between min and max (inclusive)

const min = 10
const max = 20
const result = NNumber.generateRandom(min, max)

toOrdinal

Generate ordinal string from a given number

const result = NNumber.toOrdinal(1) // '1st'
const resultTwo = NNumber.toOrdinal(101) // '101st'

fibonacci

Fibonacci Sequence

const result = NNumber.fibonacci(50) // 12586269025n

sum

Calculate the sum of an array of numbers

const result = NNumber.sum([1, 2, 3, 4, 5]) // 15

On this page