From 51959b22b151875b89ed10afdd2a633be242718a Mon Sep 17 00:00:00 2001 From: brianharvey Date: Sat, 17 Jul 2021 21:09:36 -0700 Subject: [PATCH] reshape, using Michael's suggestion --- src/lists.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/lists.js b/src/lists.js index ac46a0c1..88a39f9e 100644 --- a/src/lists.js +++ b/src/lists.js @@ -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) {