Methods
Number

Number Methods

import { number } from 'ajuda'

multiply

Description

Multiplies two numbers and checks whether either numbers or product are safe integers.

number.multiply(number: number, _number: number): number

Parameters

{number} number A number to be multiplied (throws an error if the number is unsafe).

{number} _number A number to be multiplied (throws an error if the number is unsafe).

Returns

{number} A product (throws an error if the product is unsafe).

Example

number.multiply(5000, 2)
// 10000
 
number.multiply(1_000_000, 5)
// 5000000
 
multiply(9007199254740991, 1)
// 9007199254740991 --> Largest safe integer
 
multiply(9007199254740992, 1)
// [ERR]: 9007199254740992 is an unsafe integer.
 
multiply(9007199254740991, 2)
// [ERR]: Product of both numbers is an unsafe integer

random

Description

Returns a random number between 1 and the end of the range (inclusive).

number.random(_number: number): number

Parameters

{number} _number The upper limit of the range of random numbers.

Returns

{number} A random number between 1 and the end of the range (inclusive).

Example

number.random(10) // 8
number.random(10) // 3
number.random(10) // 10

range

Description

Returns an array of numbers in a given range (inclusive of the starting and ending numbers).

number.range(start: number, end: number): number[]

Parameters

{number} start The beginning of the range.

{number} end The end of the range.

Returns

{Array<number>} An array of numbers within the given range.

Example

number.range(1, 10)
// [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]