Skip to content
Dickson Law edited this page Apr 12, 2023 · 5 revisions

Classes

List(...)

A data structure that stores entries sequentially and dynamically adjusts its size. Equivalent to DS Lists.

ListIterator(list)

An iterator class designed to efficiently loop through the list in linear time. It stores its current position in index and current value in value.

  • hasNext(): Return whether there are more values to iterate.
  • next(): Iterate to the next value.
  • remove(): Remove the current value from the list.
  • set(val): Set the current value in the list to the given value.

A for loop using ListIterator takes this form:

for (var i = list.iterator(); i.hasNext(); i.next()) {
    /* Use i.index and i.value here */
}

Ported Methods

Aliases

  • get(pos): Same as findValue(pos)

New Methods

  • clone(): Return a shallow clone of the list.
  • cloneDeep(): Same as clone(), but also making deep copies of everything in the list.
  • copyDeep(sourceList): Same as copy(sourceList), but with deep copies of everything in the source.
  • forEach(func): Call the method or script func for each value in the list. On each iteration, it will be passed the current value followed by the current position.
  • iterator(): Return a new ListIterator set to track this list.
  • mapEach(func): Set each value v in the list to func(v). If func throws undefined, the value is removed from the list.
  • toArray(): Return the list's contents in array form. Note that this is a shallow conversion --- other lists nested inside will remain as lists in the returned array.

Clone this wiki locally