From 9456b88f6b40d12419f94b2642166c3b580b9840 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Thu, 20 Mar 2025 08:18:15 +0100 Subject: [PATCH] Remove `Array.prototype.reduce` usage from the `src/core/xfa/template.js` file Using `Array.prototype.reduce` often leads to less readable code, and in these cases we can replace that with other Array-methods instead. --- src/core/xfa/template.js | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/src/core/xfa/template.js b/src/core/xfa/template.js index 4fd5031d6..594ab25a7 100644 --- a/src/core/xfa/template.js +++ b/src/core/xfa/template.js @@ -5721,12 +5721,7 @@ class Text extends ContentObject { if (typeof this[$content] === "string") { return this[$content] .split(/[\u2029\u2028\n]/) - .reduce((acc, line) => { - if (line) { - acc.push(line); - } - return acc; - }, []) + .filter(line => !!line) .join("\n"); } return this[$content][$text](); @@ -5748,18 +5743,15 @@ class Text extends ContentObject { .map(para => // Convert a paragraph into a set of (for lines) // separated by
. - para.split(/[\u2028\n]/).reduce((acc, line) => { - acc.push( - { - name: "span", - value: line, - }, - { - name: "br", - } - ); - return acc; - }, []) + para.split(/[\u2028\n]/).flatMap(line => [ + { + name: "span", + value: line, + }, + { + name: "br", + }, + ]) ) .forEach(lines => { html.children.push({