summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAya Morisawa <AyaMorisawa4869@gmail.com>2018-12-09 09:44:24 +0900
committerGitHub <noreply@github.com>2018-12-09 09:44:24 +0900
commit34235d4d443ee29690ecd42aef8f3d9fb9b31e3e (patch)
tree73fd912c9c703b230a3f6489f3b3b2e8ccce1890 /src
parentEliminate if-statement (#3564) (diff)
downloadmisskey-34235d4d443ee29690ecd42aef8f3d9fb9b31e3e.tar.gz
misskey-34235d4d443ee29690ecd42aef8f3d9fb9b31e3e.tar.bz2
misskey-34235d4d443ee29690ecd42aef8f3d9fb9b31e3e.zip
Refactor getTextCount (#3553)
Co-authored-by: Acid Chicken (硫酸鶏) <root@acid-chicken.com>
Diffstat (limited to 'src')
-rw-r--r--src/client/app/common/views/components/mfm.ts12
1 files changed, 3 insertions, 9 deletions
diff --git a/src/client/app/common/views/components/mfm.ts b/src/client/app/common/views/components/mfm.ts
index ecb22b6bc4..31d5d16600 100644
--- a/src/client/app/common/views/components/mfm.ts
+++ b/src/client/app/common/views/components/mfm.ts
@@ -10,15 +10,9 @@ import { toUnicode } from 'punycode';
import syntaxHighlight from '../../../../../mfm/syntax-highlight';
function getTextCount(tokens: Node[]): number {
- let count = 0;
- const extract = (tokens: Node[]) => {
- count += sum(tokens.filter(x => x.name === 'text').map(x => length(x.props.text)));
- tokens.filter(x => x.children).forEach(x => {
- extract(x.children);
- });
- };
- extract(tokens);
- return count;
+ const rootCount = sum(tokens.filter(x => x.name === 'text').map(x => length(x.props.text)));
+ const childrenCount = sum(tokens.filter(x => x.children).map(x => getTextCount(x.children)));
+ return rootCount + childrenCount;
}
function getChildrenCount(tokens: Node[]): number {