Category talk:Wren-seq: Difference between revisions
Content added Content deleted
(→Source code: Added Lst.multiples and Lst.powers methods.) |
(→Source code: Added Lst.expand method.) |
||
Line 634: | Line 634: | ||
// Removes all elements of 'a' from index 'start' to the end and returns it. |
// Removes all elements of 'a' from index 'start' to the end and returns it. |
||
static truncate(a, start) { clearPart(a, start, -1) } |
static truncate(a, start) { clearPart(a, start, -1) } |
||
// Expands a list 'a' in place to a length of 'newCount' |
|||
// by adding 'element' the required number of times to it. |
|||
// If the list's length is already >= newCount, does nothing. |
|||
// Returns 'a'. |
|||
static expand(a, newCount, element) { |
|||
isList_(a) |
|||
if (newCount.type != Num || !newCount.isInteger || newCount < 0) { |
|||
Fiber.abort("newCount must be a non-negative integer.") |
|||
} |
|||
if (a.count >= newCount) return a |
|||
for (i in a.count...newCount) a.add(element) |
|||
return a |
|||
} |
|||
// Returns a clone of 'a' by recursively cloning any elements which are |
// Returns a clone of 'a' by recursively cloning any elements which are |