From f6f79fb38826430f64e58b1a91d54be70659c338 Mon Sep 17 00:00:00 2001 From: Aya Morisawa Date: Sun, 9 Dec 2018 09:44:51 +0900 Subject: [PATCH] Refactor getChildrenCount (#3554) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Acid Chicken (硫酸鶏) --- src/client/app/common/views/components/mfm.ts | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/client/app/common/views/components/mfm.ts b/src/client/app/common/views/components/mfm.ts index 31d5d16600..a6487aa4fb 100644 --- a/src/client/app/common/views/components/mfm.ts +++ b/src/client/app/common/views/components/mfm.ts @@ -16,15 +16,8 @@ function getTextCount(tokens: Node[]): number { } function getChildrenCount(tokens: Node[]): number { - let count = 0; - const extract = (tokens: Node[]) => { - tokens.filter(x => x.children).forEach(x => { - count++; - extract(x.children); - }); - }; - extract(tokens); - return count; + const countTree = tokens.filter(x => x.children).map(x => getChildrenCount(x.children)); + return countTree.length + sum(countTree); } export default Vue.component('misskey-flavored-markdown', {