Skip to content

Other functions

Arthur Guiot edited this page May 19, 2018 · 2 revisions

Apply

You can easily apply a function to a number or an array:

t.apply(2, x => 2*x) // 4
t.apply([2, 4], x => x / 2) // [1, 2]

Min, Max and Sort

t.min(2, 1, 3, 4) // 1
t.max(2, 1, 3, 4) // 4
t.sort(2, 1, 3, 4) // [1, 2, 3, 4]
t.product(5, 6, 12, 8) // 2880 => BigNumber
t.sum(5, 6, 12, 8) // 31 => BigNumber

Convert to base

You can convert any number n in base 10 to any other base.

Example:

t.convertToBase(10, 2) // '1010'

t.convertToBase(1200, 64) // 'iM'

To Base 10

This function is like the opposite of the function above.

t.toBase10('iM', 64) // 1200 => BigNumber
Clone this wiki locally