Revert "Revert "reshape, using Michael's suggestion""

This reverts commit f7c5cc5832.
snap7
brianharvey 2021-07-17 21:12:26 -07:00
rodzic f7c5cc5832
commit 200e8279fe
1 zmienionych plików z 8 dodań i 4 usunięć

Wyświetl plik

@ -687,11 +687,15 @@ List.prototype.reshape = function (dimensions) {
// answer a new list formatted to fit the given dimensions.
// truncate excess elements, if any.
// pad with (repetitions of) existing elements
var src = this.ravel().itemsArray();
var size,
i = 0,
trg,
src = this.ravel().itemsArray();
// if no dimensions, report a scalar
if (dimensions.isEmpty()) return src[0];
var size = dimensions.itemsArray().reduce((a, b) => a * b),
i = 0,
trg;
size = dimensions.itemsArray().reduce((a, b) => a * b);
// make sure the items count matches the specified target dimensions
if (size < src.length) {