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) {
|
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) {
|
||||||
|
|
Reference in a new issue