Skip to content

Commit

Permalink
Avoid using Array#reduce (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
fregante authored Sep 24, 2020
1 parent e463869 commit 5fd687f
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,16 @@ const getAsString = (string, options) => {
};

const getAsDocumentFragment = (string, options) => {
return string.split(urlRegex()).reduce((fragment, text, index) => {
const fragment = document.createDocumentFragment();
for (const [index, text] of Object.entries(string.split(urlRegex()))) {
if (index % 2) { // URLs are always in odd positions
fragment.append(domify(linkify(text, options)));
} else if (text.length > 0) {
fragment.append(document.createTextNode(text));
fragment.append(text);
}
}

return fragment;
}, document.createDocumentFragment());
return fragment;
};

module.exports = (string, options) => {
Expand Down

0 comments on commit 5fd687f

Please sign in to comment.