Category talk:Wren-seq: Difference between revisions
Content added Content deleted
(Added Seq.hasAdjDups method.) |
(→Source code: Added Lst.columns method.) |
||
Line 814: | Line 814: | ||
// As 'multiples' but where 'first' and 'multiplier' are the same. |
// As 'multiples' but where 'first' and 'multiplier' are the same. |
||
static powers(first, n) { multiples(first, n, first) } |
static powers(first, n) { multiples(first, n, first) } |
||
// Builds and returns a list of corresponding columns from a non-empty list 'a' |
|||
// of rows, where each row is a non-empty list of any element type. The number |
|||
// of columns in each row must be the same. |
|||
static columns(a) { |
|||
var nr = a.count |
|||
if (nr == 0) Fiber.abort("List must contain at least one row.") |
|||
var nc = a[0].count |
|||
if (nc == 0) Fiber.abort("Rows must have at least one column.") |
|||
if (a.skip(1).any { |e| e.count != nc }) { |
|||
Fiber.abort("Rows must all have the same number of columns.") |
|||
} |
|||
var cols = List.filled(nc, null) |
|||
for (j in 0...nc) { |
|||
cols[j] = List.filled(nr, 0) |
|||
for (i in 0...nr) cols[j][i] = a[i][j] |
|||
} |
|||
return cols |
|||
} |
|||
} |
} |
||