-
Notifications
You must be signed in to change notification settings - Fork 4
Array related functions
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"
Creates an array.
[ARGS (element 1: any...)]
Example code:
[ARRAY 2 "hello" 101]
> [2, "hello", 101]
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"]
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
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 a string into an array with a specified separator.
[SPLIT "abacaba" "b"]
> ["a", "aca", "a"]
Joins an array with a separator.
[JOIN (array: array) (separator: string)]
Example code:
[JOIN [ARRAY "A" "B" "C"] " "]
> "A B C"
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]
Numbers n' Vars || Arrays || Strings || Control flow || Meta || # || How do I start?