Skip to content

Commit ec5b518

Browse files
committed
Remove Array.prototype.reduce usage from the unit-tests
Using `Array.prototype.reduce` often leads to less readable code, and in these cases we can replace it with other Array-methods instead.
1 parent 6cc37c8 commit ec5b518

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

test/unit/ui_utils_spec.js

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,8 @@ describe("ui_utils", function () {
234234
let lineTop = 0,
235235
id = 0;
236236
for (const line of lines) {
237-
const lineHeight = line.reduce(function (maxHeight, pair) {
238-
return Math.max(maxHeight, pair[1]);
239-
}, 0);
237+
const heights = line.map(pair => pair[1]);
238+
const lineHeight = Math.max(...heights);
240239
let offsetLeft = -BORDER_WIDTH;
241240
for (const [clientWidth, clientHeight] of line) {
242241
const offsetTop =
@@ -320,14 +319,12 @@ describe("ui_utils", function () {
320319
// test to the slower implementation above, for a range of scroll viewport
321320
// sizes and positions.
322321
function scrollOverDocument(pages, horizontal = false, rtl = false) {
323-
const size = pages.reduce(function (max, { div }) {
324-
return Math.max(
325-
max,
326-
horizontal
327-
? Math.abs(div.offsetLeft + div.clientLeft + div.clientWidth)
328-
: div.offsetTop + div.clientTop + div.clientHeight
329-
);
330-
}, 0);
322+
const sizes = pages.map(({ div }) =>
323+
horizontal
324+
? Math.abs(div.offsetLeft + div.clientLeft + div.clientWidth)
325+
: div.offsetTop + div.clientTop + div.clientHeight
326+
);
327+
const size = Math.max(...sizes);
331328
// The numbers (7 and 5) are mostly arbitrary, not magic: increase them to
332329
// make scrollOverDocument tests faster, decrease them to make the tests
333330
// more scrupulous, and keep them coprime to reduce the chance of missing

0 commit comments

Comments
 (0)