Category talk:Wren-seq: Difference between revisions

→‎Source code: Added Lst.multiples and Lst.powers methods.
(→‎Source code: Added Lst.between method.)
(→‎Source code: Added Lst.multiples and Lst.powers methods.)
Line 764:
static between(start, end, step) { between(start, end, step, start <= end) }
static between(start, end) { between(start, end, 1, start <= end) }
 
// Generates and returns a list of 'n' numbers starting from and including 'first'
// where each term is found by multiplying the previous one by 'multiplier'.
static multiples(first, n, multiplier) {
if (!(first is Num)) Fiber.abort("'first' must be a number.")
if (!(n is Num) || !n.isInteger || n < 1) {
Fiber.abort("'n' must be a positive integer.")
}
if (!(multiplier is Num)) Fiber.abort("'multiplier' must be a number.")
var lst = List.filled(n, 0)
lst[0] = first
if (n == 1) return lst
for (i in 1...n) {
first = first * multiplier
lst[i] = first
}
return lst
}
 
// As 'multiples' but where 'first' and 'multiplier' are the same.
static powers(first, n) { multiples(first, n, first) }
}
 
9,476

edits