Refactor loop

Don't handle last element separately

Signed-off-by: RMidhunSuresh <rmidhunsuresh@gmail.com>
This commit is contained in:
RMidhunSuresh 2021-05-11 13:31:33 +05:30
parent 03b971d898
commit 577883a1d4

View file

@ -8,12 +8,12 @@ export class MessageBodyBuilder {
fromText(text) { fromText(text) {
const components = text.split("\n"); const components = text.split("\n");
components.slice(0, -1).forEach(t => { components.flatMap(e => ["\n", e]).slice(1).forEach(e => {
linkify(t, this.insert.bind(this)); if (e === "\n")
this.insertNewline(); this.insertNewline();
else
linkify(e, this.insert.bind(this));
}); });
const [last] = components.slice(-1);
linkify(last, this.insert.bind(this));
} }
insert(text, isLink) { insert(text, isLink) {