mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-19 06:38:07 +02:00
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.
This commit is contained in:
parent
6cc37c8415
commit
ec5b5184d3
1 changed files with 8 additions and 11 deletions
|
@ -234,9 +234,8 @@ describe("ui_utils", function () {
|
||||||
let lineTop = 0,
|
let lineTop = 0,
|
||||||
id = 0;
|
id = 0;
|
||||||
for (const line of lines) {
|
for (const line of lines) {
|
||||||
const lineHeight = line.reduce(function (maxHeight, pair) {
|
const heights = line.map(pair => pair[1]);
|
||||||
return Math.max(maxHeight, pair[1]);
|
const lineHeight = Math.max(...heights);
|
||||||
}, 0);
|
|
||||||
let offsetLeft = -BORDER_WIDTH;
|
let offsetLeft = -BORDER_WIDTH;
|
||||||
for (const [clientWidth, clientHeight] of line) {
|
for (const [clientWidth, clientHeight] of line) {
|
||||||
const offsetTop =
|
const offsetTop =
|
||||||
|
@ -320,14 +319,12 @@ describe("ui_utils", function () {
|
||||||
// test to the slower implementation above, for a range of scroll viewport
|
// test to the slower implementation above, for a range of scroll viewport
|
||||||
// sizes and positions.
|
// sizes and positions.
|
||||||
function scrollOverDocument(pages, horizontal = false, rtl = false) {
|
function scrollOverDocument(pages, horizontal = false, rtl = false) {
|
||||||
const size = pages.reduce(function (max, { div }) {
|
const sizes = pages.map(({ div }) =>
|
||||||
return Math.max(
|
horizontal
|
||||||
max,
|
? Math.abs(div.offsetLeft + div.clientLeft + div.clientWidth)
|
||||||
horizontal
|
: div.offsetTop + div.clientTop + div.clientHeight
|
||||||
? Math.abs(div.offsetLeft + div.clientLeft + div.clientWidth)
|
);
|
||||||
: div.offsetTop + div.clientTop + div.clientHeight
|
const size = Math.max(...sizes);
|
||||||
);
|
|
||||||
}, 0);
|
|
||||||
// The numbers (7 and 5) are mostly arbitrary, not magic: increase them to
|
// The numbers (7 and 5) are mostly arbitrary, not magic: increase them to
|
||||||
// make scrollOverDocument tests faster, decrease them to make the tests
|
// make scrollOverDocument tests faster, decrease them to make the tests
|
||||||
// more scrupulous, and keep them coprime to reduce the chance of missing
|
// more scrupulous, and keep them coprime to reduce the chance of missing
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue