Refactor getChildrenCount (#3554)

Co-authored-by: Acid Chicken (硫酸鶏) <root@acid-chicken.com>
This commit is contained in:
Aya Morisawa 2018-12-09 09:44:51 +09:00 committed by GitHub
parent 34235d4d44
commit f6f79fb388
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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', {