Refactor loop
Don't handle last element separately Signed-off-by: RMidhunSuresh <rmidhunsuresh@gmail.com>
This commit is contained in:
parent
03b971d898
commit
577883a1d4
1 changed files with 5 additions and 5 deletions
|
@ -8,12 +8,12 @@ export class MessageBodyBuilder {
|
|||
|
||||
fromText(text) {
|
||||
const components = text.split("\n");
|
||||
components.slice(0, -1).forEach(t => {
|
||||
linkify(t, this.insert.bind(this));
|
||||
this.insertNewline();
|
||||
components.flatMap(e => ["\n", e]).slice(1).forEach(e => {
|
||||
if (e === "\n")
|
||||
this.insertNewline();
|
||||
else
|
||||
linkify(e, this.insert.bind(this));
|
||||
});
|
||||
const [last] = components.slice(-1);
|
||||
linkify(last, this.insert.bind(this));
|
||||
}
|
||||
|
||||
insert(text, isLink) {
|
||||
|
|
Reference in a new issue