Difference between revisions of "List"

From MiniScript Wiki
Jump to navigation Jump to search
m (Remove empty list)
(Added method list)
Line 2: Line 2:
  
 
A list is mutable, ordered sequence of values.  A list literal is defined by a comma-separated series of values enclosed in square brackets.
 
A list is mutable, ordered sequence of values.  A list literal is defined by a comma-separated series of values enclosed in square brackets.
 +
 +
Example:
  
 
<ms>
 
<ms>
Line 7: Line 9:
 
words = ["one", "two", "three", "four", "five"]
 
words = ["one", "two", "three", "four", "five"]
 
</ms>
 
</ms>
 +
 +
== Methods ==
 +
 +
{| class="wikitable"
 +
|-
 +
! Method !! Description
 +
|-
 +
| len || Returns the length of the list
 +
|-
 +
| indexOf(x) || Returns the index of the first occurrence of <c>x</c> in the list, or <c>null</c> if not found
 +
|-
 +
| push(x) || Adds the element <c>x</c> to the end of the list
 +
|-
 +
| remove(i) || Removes the element '''at index''' <c>i</c>
 +
|-
 +
| pop || Removes the ''last'' element of the list, and returns it
 +
|-
 +
| pull || Removes the ''first'' element of the list, and returns it
 +
|-
 +
| sum || Returns the sum of all numeric values in the list
 +
|-
 +
| sort || Mutates the list by sorting its elements ''in place''
 +
|-
 +
| shuffle || Mutates the list by re-ordering its elements randomly
 +
|-
 +
| join(x) || Returns a string with all list elements "joined" by element <c>x</c>
 +
|}
  
 
[[Category:Language]]
 
[[Category:Language]]

Revision as of 23:18, 5 December 2021

list is one of the core data types in MiniScript.

A list is mutable, ordered sequence of values. A list literal is defined by a comma-separated series of values enclosed in square brackets.

Example:

numbers = [1, 2, 3, 4, 5]
words = ["one", "two", "three", "four", "five"]

Methods

Method Description
len Returns the length of the list
indexOf(x) Returns the index of the first occurrence of x in the list, or null if not found
push(x) Adds the element x to the end of the list
remove(i) Removes the element at index i
pop Removes the last element of the list, and returns it
pull Removes the first element of the list, and returns it
sum Returns the sum of all numeric values in the list
sort Mutates the list by sorting its elements in place
shuffle Mutates the list by re-ordering its elements randomly
join(x) Returns a string with all list elements "joined" by element x


This article is a stub. You can help the MiniScript Wiki by expanding it.