resize

Time# resize

A collection of functions that resizes the elements of an array or the array itself

Methods

# (static) by_product(input, byopt, roundopt, remove_0sopt) → {Array.<Number>}

Returns a given array with its elements "resized" by a given multiplier.

Parameters:
Name Type Attributes Default Description
input Array.<Number>

The original array.

by Number <optional>
1

The number by which to resize the elements

round false | "up" | "down" | "closest" <optional>
false

When not false, this determines how the elements are to be rounded when not integers

remove_0s Boolean <optional>
false

When true, 0s will be completely erased from the array.

Source:
Returns:

The resized input

Type
Array.<Number>
Example
let time = new Time()
time.resize.by_product([2,4,1,3],0.45) // returns [ 0.9, 1.8, 0.45, 1.35 ]
time.resize.by_product([2,4,1,3],0.45,"up") // returns [ 1, 2, 1, 2 ]
time.resize.by_product([2,4,1,3],0.45,"closest",false) // returns [ 1, 2, 0, 1 ]
time.resize.by_product([2,4,1,3],0.45,"closest",true) // returns [ 1, 2, 1 ]

# (static) by_sum(input, byopt, remove_0sopt) → {Array.<Number>}

Returns a given array with its elements "resized" by an added sum.

Parameters:
Name Type Attributes Default Description
input Array.<Number>

The original array.

by Number <optional>
1

The number by which to resize the elements

remove_0s Boolean <optional>
false

When true, 0s will be completely erased from the array.

Source:
Returns:

The resized input

Type
Array.<Number>
Example
let time = new Time()
time.resize.by_sum([2,4,1,3],-1,false) //[ 1, 3, 0, 2 ]
time.resize.by_sum([2,4,1,3],-1,true) //[ 1, 3, 2 ]