Skip to content

Array related functions

Inferno edited this page Apr 25, 2023 · 9 revisions

args

An array of arguments inputted by the user. Acts like [INDEX] if given an index.

[ARGS (index: integer or blank)]

Example code:

(in this example, the user runs b/tag example 2 hello 101)

[ARGS]
> [2, "hello", 101]

[ARGS 1]
> "hello"

array

Creates an array.

[ARGS (element 1: any...)]

Example code:

[ARRAY 2 "hello" 101]
> [2, "hello", 101]

choose

Randomly chooses a item inside an array, a character from a string, or from one of multiple items.

[CHOOSE (element: array or string)]
[CHOOSE (element 1: any...)]

Example code:

[CHOOSE [ARRAY 2 "hello" 101]]
> "hello"

[CHOOSE "hello"]
> "e"

[LOOP 10 [CHOOSE [ARRAY 2 "hello" 101]]]
> ["hello", 2, 101, "hello", 2, 101, 2, 101, 101, "hello"]

find

Finds the index of an item in an array.

[FIND (arrayToLook: array) (value: any)]

Example code:

[FIND [ARRAY 1 2 3] 1]
> 0

[FIND [ARRAY 1 2 3] 6]
> -1

index

Get an item inside an array at a certain index.]

`[INDEX (array: array) (indexToGet: int)]

[INDEX [ARRAY 2 "hello" 101] 0]
> 2

[INDEX [ARRAY 2 "hello" 101] 1]
> "hello"

You can also use negative numbers:

[INDEX [ARRAY 2 "hello" 101] -1]
> 101

split

Split a string into an array with a specified separator.

[SPLIT "abacaba" "b"]
> ["a", "aca", "a"] 

join

Joins an array with a separator.

[JOIN (array: array) (separator: string)]

Example code:

[JOIN [ARRAY "A" "B" "C"] " "]
> "A B C"

map

Iterates over an array. map.iterator and map.i is set for each element in the array.

[MAP (function: function) (iterated: array)]

Example code:

> [MAP [ADD [VAR map.iterator] 5] [ARRAY 1 2 3]]
[6, 7, 8]
Clone this wiki locally