Skip to content

Latest commit

 

History

History
67 lines (37 loc) · 1.69 KB

hydra-arrays.md

File metadata and controls

67 lines (37 loc) · 1.69 KB

hydra-arrays

Extends the functionality of arrays in Hydra, letting you operate between different arrays and generate new ones.

Operators

Regular operators

.add, .sub, .mult, .div, .mod

These will let you add either a constant or an array to another array. If the second array is smaller than the first one, it simply stops there. For example:

[0,1,2,3].add(1)     == [1,2,3,4]
[0,1,2,3].add([1,2]) == [1,3,2,3]

Wrap operators

.addWrap, .subWrap, .multWrap, .divWrap, .modWrap

These are just like the regular operators, but if the second array is smaller than the first one, it'll repeat itself until going through every single element in the first array.

[0,1,2,3].add([1,2])     == [1,3,2,3]
[0,1,2,3].addWrap([1,2]) == [1,3,3,5]

Methods

shuffle

.shuffle()

Will return a shuffled version of any array.

zfill

.zfill(length, z = 0)

Will concat z to the array repeatedly until the array reaches the desired length. Inspired by python's zfill, however, the one shown here adds the zeroes at the end of the array.

rotate

.rotate(n) / .rot(n)

Will rotate the array by n steps. Works with negative values.

Generators

Array.random

Array.random(length = 10, min = 0, max = 1)

Generates a new array of a given length and fills it with random values between the range min to max.

Array.range

Array.range(start, end, step = 1)

Generates a new array of numbers starting from start, then each element increases by step until end (non-inclusive).

Array.run

Array.range(end = 10, step = 1)

Generates a new array of numbers starting from 0, then each element increses by step until end (non-inclusive).