Skip to main content

List functions

The following functions and variables are part the DekiScript and MindTouch runtime environment.

list.apply(list, expression) : list

Create a new list by applying the expression to each item.

Name Type Description
list list list value
expression str expression to apply (use '$' to refer to the current item)

list.average(list, expression) : num

Get average of values in list.

Name Type Description
list list list value
expression str (optional) expression to fetch value (use '$' to refer to the current item; default: $)

list.collect(list, key) : list

Collect all values from each map inside the list.

Name Type Description
list list list of maps
key str key for value to collect

list.combine(keys, values) : map

Combine two lists into a map.

Name Type Description
keys list list of keys
values list list of values

list.contains(list, value, ignorecase) : bool

Check if list contains the given value.

Name Type Description
list list list value
value any value to check for
ignorecase bool (optional) ignore case (default: false)

list.count(list, condition) : num

Count the number of items for which the condition succeeds.

Name Type Description
list list list value
condition str condition to execute for each item (use '$' to refer to the item)

list.groupby(list, expression) : map

Group items in list by common expression value.

Name Type Description
list list list value
expression str expression to apply for grouping (use '$' to refer to the current item)

list.indexesof(list, value) : list

Find all index positions of the given value.

Name Type Description
list list list value
value any value to check for

list.indexof(list, value) : num

Find the index position of the given value.

Name Type Description
list list list value
value any value to check for

list.intersect(first, second, condition) : list

Compute the list of values that are common to the first and second list.

Name Type Description
first list first list
second list second list
condition str (optional) expression to determine if item from the first list should be included in final list (return true to include, false to exclude; use '$left' and '$right' to refer to the current item from the first and seconds lists respectively; default: equality condition)

list.lastindexof(list, value) : num

Find the last index position of the given value.

Name Type Description
list list list value
value any value to check for

list.max(list, expression) : num

Get largest value in list.

Name Type Description
list list list value
expression str (optional) expression to fetch value (use '$' to refer to the current item; default: $)

list.min(list, expression) : num

Get smallest value in list.

Name Type Description
list list list value
expression str (optional) expression to fetch value (use '$' to refer to the current item; default: $)

list.new(size, value) : list

Create a list of a given size.

Name Type Description
size num size of the list
value any (optional) intial value for list entry (default: nil)

list.orderby(list, keys) : list

Sort items in list using key names.

Name Type Description
list list list value
keys any key name or list of key names; sort direction is controlled by appendending " ascending" or " descending" to the key(s); when omitted, the direction is asending by default

list.random(list) : any

Get a random item from the list.

Name Type Description
list list list value

list.reduce(list, expression, value) : any

Combine all values in list into a single value using the supplied expression.

Name Type Description
list list list value
expression str expression to compute combined value (use '$value' and '$item' to refer to the current value and item, respectively)
value any (optional) starting value (default: nil)

list.reverse(list) : list

Reverse the items in a list.

Name Type Description
list list list value
var lst = ["one","two","three","four","five"];
list.reverse(lst);

list.select(list, condition) : list

Create a list that only contains values for which the condition succeeds.

Name Type Description
list list list value
condition str condition to execute for each item (use '$' to refer to the item)

list.sort(list, key, reverse, compare) : list

Sort the items in a list.

Name Type Description
list list list of values
key any (optional) key for value if list contains maps (default: nil)
reverse bool (optional) sort in reverse order (default: false)
compare str (optional) compare two items (return -1 if left item less than the right item, 0 if they are equal, and +1 if the left item is greater than the right item; use '$left' and '$right' to refer to the left and right items respectively)

list.splice(list, start, length, values) : list

Split a list and insert new items into it.

Name Type Description
list list list value
start num copy all values before the start offset; if negative, offset is relative to end of list
length num (optional) number of elements to skip; if negative, relative to length of list (default: all)
values list (optional) values to append after start offset (default: none)

 

Example

var lst = ["one","two","three","four","five"];
list.splice(lst,2);

list.sum(list, expression) : num

Get sum of values in list.

Name Type Description
list list list value
expression str (optional) expression to fetch value (use '$' to refer to the current item; default: $)

 

  • Was this article helpful?