Difference between revisions of "Map"
Jump to navigation
Jump to search
m |
(Added base methods for the map class) |
||
| Line 1: | Line 1: | ||
<c>map</c> is one of the core [[:Category:Data Types|data types]] in MiniScript. | <c>map</c> is one of the core [[:Category:Data Types|data types]] in MiniScript. | ||
| + | |||
| + | == Methods == | ||
| + | |||
| + | {| class="wikitable" | ||
| + | |- | ||
| + | ! Method !! Description | ||
| + | |- | ||
| + | | hasIndex(''key'') || Returns true if the map contains ''key'' | ||
| + | |- | ||
| + | | indexes || Returns a list of the map keys | ||
| + | |- | ||
| + | | indexOf(''value'', ''after'') || Returns the key of the first occurrence of ''value'' in the map, or <c>null</c> if not found. Does not search inheritance chain. | ||
| + | |- | ||
| + | | len || Returns the number of key/value pairs contained in the map | ||
| + | |- | ||
| + | | pop || Removes the most recently added key/value pair and returns the key | ||
| + | |- | ||
| + | | push ''key'' || Adds the ''key'' to the map and assigns a value of 1 | ||
| + | |- | ||
| + | | pull || Same as pop. | ||
| + | |- | ||
| + | | shuffle || Mutates the map by randomly re-ordering the values assigned to each key within the map | ||
| + | |- | ||
| + | | sum || Returns the sum of all numeric values in the map | ||
| + | |- | ||
| + | | remove ''key'' || Removes the key/value pair at ''key'' | ||
| + | |- | ||
| + | | replace ''oldValue'', ''newValue'', ''maxCount'' || Mutates the map by replacing occurrences of ''oldValue'' with ''newValue'' at most ''maxCount'', if specified. If ''maxCount'' is omitted it replaces '''all''' occurrences. | ||
| + | |- | ||
| + | | values || Returns a list values within the map | ||
| + | |} | ||
| + | |||
| + | == See also == | ||
| + | * [[mapUtil]] - for additional functions on a list | ||
[[Category:Language]] | [[Category:Language]] | ||
[[Category:Data Types]] | [[Category:Data Types]] | ||
| − | |||
| − | |||
Revision as of 00:55, 2 September 2025
map is one of the core data types in MiniScript.
Methods
| Method | Description |
|---|---|
| hasIndex(key) | Returns true if the map contains key |
| indexes | Returns a list of the map keys |
| indexOf(value, after) | Returns the key of the first occurrence of value in the map, or null if not found. Does not search inheritance chain.
|
| len | Returns the number of key/value pairs contained in the map |
| pop | Removes the most recently added key/value pair and returns the key |
| push key | Adds the key to the map and assigns a value of 1 |
| pull | Same as pop. |
| shuffle | Mutates the map by randomly re-ordering the values assigned to each key within the map |
| sum | Returns the sum of all numeric values in the map |
| remove key | Removes the key/value pair at key |
| replace oldValue, newValue, maxCount | Mutates the map by replacing occurrences of oldValue with newValue at most maxCount, if specified. If maxCount is omitted it replaces all occurrences. |
| values | Returns a list values within the map |
See also
- mapUtil - for additional functions on a list